[llvm-branch-commits] [lld] [llvm] [CGData][llvm-cgdata] Support for stable function map (PR #112664)
https://github.com/kyulee-com updated https://github.com/llvm/llvm-project/pull/112664 >From f6fc25953b8f5109abb968c43ebc7d53f2e475db Mon Sep 17 00:00:00 2001 From: Kyungwoo Lee Date: Mon, 9 Sep 2024 19:38:05 -0700 Subject: [PATCH] [CGData][llvm-cgdata] Support for stable function map This introduces a new cgdata format for stable function maps. The raw data is embedded in the __llvm_merge section during compile time. This data can be read and merged using the llvm-cgdata tool, into an indexed cgdata file. Consequently, the tool is now capable of handling either outlined hash trees, stable function maps, or both, as they are orthogonal. --- lld/test/MachO/cgdata-generate.s | 6 +- llvm/docs/CommandGuide/llvm-cgdata.rst| 16 ++-- llvm/include/llvm/CGData/CodeGenData.h| 24 +- llvm/include/llvm/CGData/CodeGenData.inc | 12 ++- llvm/include/llvm/CGData/CodeGenDataReader.h | 29 ++- llvm/include/llvm/CGData/CodeGenDataWriter.h | 17 +++- llvm/lib/CGData/CodeGenData.cpp | 30 --- llvm/lib/CGData/CodeGenDataReader.cpp | 63 +- llvm/lib/CGData/CodeGenDataWriter.cpp | 30 ++- llvm/test/tools/llvm-cgdata/empty.test| 8 +- llvm/test/tools/llvm-cgdata/error.test| 13 +-- .../merge-combined-funcmap-hashtree.test | 66 +++ .../llvm-cgdata/merge-funcmap-archive.test| 83 +++ .../llvm-cgdata/merge-funcmap-concat.test | 78 + .../llvm-cgdata/merge-funcmap-double.test | 79 ++ .../llvm-cgdata/merge-funcmap-single.test | 36 ...chive.test => merge-hashtree-archive.test} | 8 +- ...concat.test => merge-hashtree-concat.test} | 6 +- ...double.test => merge-hashtree-double.test} | 8 +- ...single.test => merge-hashtree-single.test} | 4 +- llvm/tools/llvm-cgdata/llvm-cgdata.cpp| 48 --- 21 files changed, 577 insertions(+), 87 deletions(-) create mode 100644 llvm/test/tools/llvm-cgdata/merge-combined-funcmap-hashtree.test create mode 100644 llvm/test/tools/llvm-cgdata/merge-funcmap-archive.test create mode 100644 llvm/test/tools/llvm-cgdata/merge-funcmap-concat.test create mode 100644 llvm/test/tools/llvm-cgdata/merge-funcmap-double.test create mode 100644 llvm/test/tools/llvm-cgdata/merge-funcmap-single.test rename llvm/test/tools/llvm-cgdata/{merge-archive.test => merge-hashtree-archive.test} (91%) rename llvm/test/tools/llvm-cgdata/{merge-concat.test => merge-hashtree-concat.test} (93%) rename llvm/test/tools/llvm-cgdata/{merge-double.test => merge-hashtree-double.test} (90%) rename llvm/test/tools/llvm-cgdata/{merge-single.test => merge-hashtree-single.test} (92%) diff --git a/lld/test/MachO/cgdata-generate.s b/lld/test/MachO/cgdata-generate.s index 174df39d666c5d..f942ae07f64e0e 100644 --- a/lld/test/MachO/cgdata-generate.s +++ b/lld/test/MachO/cgdata-generate.s @@ -3,12 +3,12 @@ # RUN: rm -rf %t; split-file %s %t -# Synthesize raw cgdata without the header (24 byte) from the indexed cgdata. +# Synthesize raw cgdata without the header (32 byte) from the indexed cgdata. # RUN: llvm-cgdata --convert --format binary %t/raw-1.cgtext -o %t/raw-1.cgdata -# RUN: od -t x1 -j 24 -An %t/raw-1.cgdata | tr -d '\n\r\t' | sed 's/[ ][ ]*/ /g; s/^[ ]*//; s/[ ]*$//; s/[ ]/,0x/g; s/^/0x/' > %t/raw-1-bytes.txt +# RUN: od -t x1 -j 32 -An %t/raw-1.cgdata | tr -d '\n\r\t' | sed 's/[ ][ ]*/ /g; s/^[ ]*//; s/[ ]*$//; s/[ ]/,0x/g; s/^/0x/' > %t/raw-1-bytes.txt # RUN: sed "s//$(cat %t/raw-1-bytes.txt)/g" %t/merge-template.s > %t/merge-1.s # RUN: llvm-cgdata --convert --format binary %t/raw-2.cgtext -o %t/raw-2.cgdata -# RUN: od -t x1 -j 24 -An %t/raw-2.cgdata | tr -d '\n\r\t' | sed 's/[ ][ ]*/ /g; s/^[ ]*//; s/[ ]*$//; s/[ ]/,0x/g; s/^/0x/' > %t/raw-2-bytes.txt +# RUN: od -t x1 -j 32 -An %t/raw-2.cgdata | tr -d '\n\r\t' | sed 's/[ ][ ]*/ /g; s/^[ ]*//; s/[ ]*$//; s/[ ]/,0x/g; s/^/0x/' > %t/raw-2-bytes.txt # RUN: sed "s//$(cat %t/raw-2-bytes.txt)/g" %t/merge-template.s > %t/merge-2.s # RUN: llvm-mc -filetype obj -triple arm64-apple-darwin %t/merge-1.s -o %t/merge-1.o diff --git a/llvm/docs/CommandGuide/llvm-cgdata.rst b/llvm/docs/CommandGuide/llvm-cgdata.rst index f592e1508844ee..0670decd087e39 100644 --- a/llvm/docs/CommandGuide/llvm-cgdata.rst +++ b/llvm/docs/CommandGuide/llvm-cgdata.rst @@ -11,15 +11,13 @@ SYNOPSIS DESCRIPTION --- -The :program:llvm-cgdata utility parses raw codegen data embedded -in compiled binary files and merges them into a single .cgdata file. -It can also inspect and manipulate .cgdata files. -Currently, the tool supports saving and restoring outlined hash trees, -enabling global function outlining across modules, allowing for more -efficient function outlining in subsequent compilations. -The design is extensible, allowing for the incorporation of additional -codegen summaries and optimization techniques, such as global function -merging, in the futur
[llvm-branch-commits] [llvm] [CGData] Global Merge Functions (PR #112671)
https://github.com/kyulee-com created https://github.com/llvm/llvm-project/pull/112671 None >From 2a690c75924de5feadb4a582d76822b4d4d1d2cf Mon Sep 17 00:00:00 2001 From: Kyungwoo Lee Date: Fri, 30 Aug 2024 00:09:09 -0700 Subject: [PATCH] [CGData] Global Merge Functions --- llvm/include/llvm/CGData/CodeGenData.h| 11 + llvm/include/llvm/InitializePasses.h | 1 + llvm/include/llvm/LinkAllPasses.h | 1 + llvm/include/llvm/Passes/CodeGenPassBuilder.h | 1 + llvm/include/llvm/Transforms/IPO.h| 2 + .../Transforms/IPO/GlobalMergeFunctions.h | 73 ++ llvm/lib/CodeGen/TargetPassConfig.cpp | 3 + llvm/lib/LTO/LTO.cpp | 1 + llvm/lib/Transforms/IPO/CMakeLists.txt| 2 + .../Transforms/IPO/GlobalMergeFunctions.cpp | 669 ++ .../ThinLTO/AArch64/cgdata-merge-local.ll | 62 ++ .../test/ThinLTO/AArch64/cgdata-merge-read.ll | 82 +++ .../AArch64/cgdata-merge-two-rounds.ll| 68 ++ .../ThinLTO/AArch64/cgdata-merge-write.ll | 97 +++ llvm/tools/llvm-lto2/CMakeLists.txt | 1 + llvm/tools/llvm-lto2/llvm-lto2.cpp| 6 + 16 files changed, 1080 insertions(+) create mode 100644 llvm/include/llvm/Transforms/IPO/GlobalMergeFunctions.h create mode 100644 llvm/lib/Transforms/IPO/GlobalMergeFunctions.cpp create mode 100644 llvm/test/ThinLTO/AArch64/cgdata-merge-local.ll create mode 100644 llvm/test/ThinLTO/AArch64/cgdata-merge-read.ll create mode 100644 llvm/test/ThinLTO/AArch64/cgdata-merge-two-rounds.ll create mode 100644 llvm/test/ThinLTO/AArch64/cgdata-merge-write.ll diff --git a/llvm/include/llvm/CGData/CodeGenData.h b/llvm/include/llvm/CGData/CodeGenData.h index 5d7c74725ccef1..da0e412f2a0e03 100644 --- a/llvm/include/llvm/CGData/CodeGenData.h +++ b/llvm/include/llvm/CGData/CodeGenData.h @@ -145,6 +145,9 @@ class CodeGenData { const OutlinedHashTree *getOutlinedHashTree() { return PublishedHashTree.get(); } + const StableFunctionMap *getStableFunctionMap() { +return PublishedStableFunctionMap.get(); + } /// Returns true if we should write codegen data. bool emitCGData() { return EmitCGData; } @@ -169,10 +172,18 @@ inline bool hasOutlinedHashTree() { return CodeGenData::getInstance().hasOutlinedHashTree(); } +inline bool hasStableFunctionMap() { + return CodeGenData::getInstance().hasStableFunctionMap(); +} + inline const OutlinedHashTree *getOutlinedHashTree() { return CodeGenData::getInstance().getOutlinedHashTree(); } +inline const StableFunctionMap *getStableFunctionMap() { + return CodeGenData::getInstance().getStableFunctionMap(); +} + inline bool emitCGData() { return CodeGenData::getInstance().emitCGData(); } inline void diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h index 4352099d6dbb99..9aa36d5bb7f801 100644 --- a/llvm/include/llvm/InitializePasses.h +++ b/llvm/include/llvm/InitializePasses.h @@ -123,6 +123,7 @@ void initializeGCEmptyBasicBlocksPass(PassRegistry &); void initializeGCMachineCodeAnalysisPass(PassRegistry &); void initializeGCModuleInfoPass(PassRegistry &); void initializeGVNLegacyPassPass(PassRegistry &); +void initializeGlobalMergeFuncPass(PassRegistry &); void initializeGlobalMergePass(PassRegistry &); void initializeGlobalsAAWrapperPassPass(PassRegistry &); void initializeHardwareLoopsLegacyPass(PassRegistry &); diff --git a/llvm/include/llvm/LinkAllPasses.h b/llvm/include/llvm/LinkAllPasses.h index 92b59a66567c95..ea3609a2b4bc71 100644 --- a/llvm/include/llvm/LinkAllPasses.h +++ b/llvm/include/llvm/LinkAllPasses.h @@ -79,6 +79,7 @@ struct ForcePassLinking { (void)llvm::createDomOnlyViewerWrapperPassPass(); (void)llvm::createDomViewerWrapperPassPass(); (void)llvm::createAlwaysInlinerLegacyPass(); +(void)llvm::createGlobalMergeFuncPass(); (void)llvm::createGlobalsAAWrapperPass(); (void)llvm::createInstSimplifyLegacyPass(); (void)llvm::createInstructionCombiningPass(); diff --git a/llvm/include/llvm/Passes/CodeGenPassBuilder.h b/llvm/include/llvm/Passes/CodeGenPassBuilder.h index 13bc4700d87029..96b5b815132bc0 100644 --- a/llvm/include/llvm/Passes/CodeGenPassBuilder.h +++ b/llvm/include/llvm/Passes/CodeGenPassBuilder.h @@ -74,6 +74,7 @@ #include "llvm/Target/CGPassBuilderOption.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Transforms/CFGuard.h" +#include "llvm/Transforms/IPO/GlobalMergeFunctions.h" #include "llvm/Transforms/Scalar/ConstantHoisting.h" #include "llvm/Transforms/Scalar/LoopPassManager.h" #include "llvm/Transforms/Scalar/LoopStrengthReduce.h" diff --git a/llvm/include/llvm/Transforms/IPO.h b/llvm/include/llvm/Transforms/IPO.h index ee0e35aa618325..86a8654f56997c 100644 --- a/llvm/include/llvm/Transforms/IPO.h +++ b/llvm/include/llvm/Transforms/IPO.h @@ -55,6 +55,8 @@ enum class PassSummaryAction { Export, ///< Export information to summary. }; +Pass *createGlobalMerg
[llvm-branch-commits] [lld] [CGData][lld-macho] Add Global Merge Func Pass (PR #112674)
https://github.com/kyulee-com created https://github.com/llvm/llvm-project/pull/112674 None >From 36978c1da750496941705b284b3c34495b6f7386 Mon Sep 17 00:00:00 2001 From: Kyungwoo Lee Date: Wed, 16 Oct 2024 22:56:38 -0700 Subject: [PATCH] [CGData][lld-macho] Add Global Merge Func Pass --- lld/MachO/CMakeLists.txt | 2 + lld/MachO/Driver.cpp | 18 +- lld/MachO/InputSection.h | 1 + lld/MachO/LTO.cpp | 7 +++ lld/test/MachO/cgdata-generate-merge.s | 85 ++ 5 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 lld/test/MachO/cgdata-generate-merge.s diff --git a/lld/MachO/CMakeLists.txt b/lld/MachO/CMakeLists.txt index ecf6ce609e59f2..137fe4939b4457 100644 --- a/lld/MachO/CMakeLists.txt +++ b/lld/MachO/CMakeLists.txt @@ -41,9 +41,11 @@ add_lld_library(lldMachO BitReader BitWriter CGData + CodeGen Core DebugInfoDWARF Demangle + IPO LTO MC ObjCARCOpts diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp index ab4abb1fa97efc..59c24a06a2cb20 100644 --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -1326,7 +1326,8 @@ static void codegenDataGenerate() { TimeTraceScope timeScope("Generating codegen data"); OutlinedHashTreeRecord globalOutlineRecord; - for (ConcatInputSection *isec : inputSections) + StableFunctionMapRecord globalMergeRecord; + for (ConcatInputSection *isec : inputSections) { if (isec->getSegName() == segment_names::data && isec->getName() == section_names::outlinedHashTree) { // Read outlined hash tree from each section. @@ -1337,10 +1338,25 @@ static void codegenDataGenerate() { // Merge it to the global hash tree. globalOutlineRecord.merge(localOutlineRecord); } +if (isec->getSegName() == segment_names::data && +isec->getName() == section_names::functionmap) { + // Read stable functions from each section. + StableFunctionMapRecord localMergeRecord; + auto *data = isec->data.data(); + localMergeRecord.deserialize(data); + + // Merge it to the global function map. + globalMergeRecord.merge(localMergeRecord); +} + } + + globalMergeRecord.finalize(); CodeGenDataWriter Writer; if (!globalOutlineRecord.empty()) Writer.addRecord(globalOutlineRecord); + if (!globalMergeRecord.empty()) +Writer.addRecord(globalMergeRecord); std::error_code EC; auto fileName = config->codegenDataGeneratePath; diff --git a/lld/MachO/InputSection.h b/lld/MachO/InputSection.h index 7ef0e31066f372..b86520d36cda5b 100644 --- a/lld/MachO/InputSection.h +++ b/lld/MachO/InputSection.h @@ -339,6 +339,7 @@ constexpr const char const_[] = "__const"; constexpr const char lazySymbolPtr[] = "__la_symbol_ptr"; constexpr const char lazyBinding[] = "__lazy_binding"; constexpr const char literals[] = "__literals"; +constexpr const char functionmap[] = "__llvm_merge"; constexpr const char moduleInitFunc[] = "__mod_init_func"; constexpr const char moduleTermFunc[] = "__mod_term_func"; constexpr const char nonLazySymbolPtr[] = "__nl_symbol_ptr"; diff --git a/lld/MachO/LTO.cpp b/lld/MachO/LTO.cpp index 28f5290edb58e3..9bddf9a6445f6d 100644 --- a/lld/MachO/LTO.cpp +++ b/lld/MachO/LTO.cpp @@ -25,6 +25,7 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/Transforms/IPO.h" #include "llvm/Transforms/ObjCARC.h" using namespace lld; @@ -38,6 +39,8 @@ static std::string getThinLTOOutputFile(StringRef modulePath) { config->thinLTOPrefixReplaceNew); } +extern cl::opt EnableGlobalMergeFunc; + static lto::Config createConfig() { lto::Config c; c.Options = initTargetOptionsFromCodeGenFlags(); @@ -49,6 +52,10 @@ static lto::Config createConfig() { c.MAttrs = getMAttrs(); c.DiagHandler = diagnosticHandler; + c.PreCodeGenPassesHook = [](legacy::PassManager &pm) { +if (EnableGlobalMergeFunc) + pm.add(createGlobalMergeFuncPass()); + }; c.AlwaysEmitRegularLTOObj = !config->ltoObjPath.empty(); c.TimeTraceEnabled = config->timeTraceEnabled; diff --git a/lld/test/MachO/cgdata-generate-merge.s b/lld/test/MachO/cgdata-generate-merge.s new file mode 100644 index 00..3f7fb6777bc3cf --- /dev/null +++ b/lld/test/MachO/cgdata-generate-merge.s @@ -0,0 +1,85 @@ +# UNSUPPORTED: system-windows +# REQUIRES: aarch64 + +# RUN: rm -rf %t; split-file %s %t + +# Synthesize raw cgdata without the header (32 byte) from the indexed cgdata. +# RUN: llvm-cgdata --convert --format binary %t/raw-1.cgtext -o %t/raw-1.cgdata +# RUN: od -t x1 -j 32 -An %t/raw-1.cgdata | tr -d '\n\r\t' | sed 's/[ ][ ]*/ /g; s/^[ ]*//; s/[ ]*$//; s/[ ]/,0x/g; s/^/0x/' > %t/raw-1-bytes.txt +# RUN: sed "s//$(cat %t/raw-1-bytes.txt)/g" %t/merge-template.s > %t/merge-1.s +# RUN: llvm-cgdata --convert --format binary %t/raw-2.cgtext -o %t/raw-2.cgdata +# RUN: od -t
[llvm-branch-commits] [flang] [llvm] [Flang] Move runtime library files to clang-rt. NFC (PR #110298)
Meinersbur wrote: Removed the library name (`flang_rt`, `CufRuntime`) from the include paths and put the CufRuntime file into a CUDA subdirectory. IMHO this violates the basic convention that when including a header file, the path indicates what library you will have to link to. E.g. with `#include `, you will have to link to `-lLLVMSupport`. https://github.com/llvm/llvm-project/pull/110298 ___ 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] Reject if constexpr in C (#112685) (PR #112697)
https://github.com/Fznamznon created https://github.com/llvm/llvm-project/pull/112697 Fixes https://github.com/llvm/llvm-project/issues/112587 >From 35dd9fa1ca01c0c7204a4d8677c615c0956fd397 Mon Sep 17 00:00:00 2001 From: Mariya Podchishchaeva Date: Thu, 17 Oct 2024 13:42:35 +0200 Subject: [PATCH] [clang] Reject if constexpr in C (#112685) Fixes https://github.com/llvm/llvm-project/issues/112587 --- clang/lib/Parse/ParseStmt.cpp | 11 +++ clang/test/Sema/constexpr.c | 7 +++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp index 22d38adc28ebe9..3ac1f0fa27f83f 100644 --- a/clang/lib/Parse/ParseStmt.cpp +++ b/clang/lib/Parse/ParseStmt.cpp @@ -1508,10 +1508,13 @@ StmtResult Parser::ParseIfStatement(SourceLocation *TrailingElseLoc) { SourceLocation ConstevalLoc; if (Tok.is(tok::kw_constexpr)) { -Diag(Tok, getLangOpts().CPlusPlus17 ? diag::warn_cxx14_compat_constexpr_if -: diag::ext_constexpr_if); -IsConstexpr = true; -ConsumeToken(); +// C23 supports constexpr keyword, but only for object definitions. +if (getLangOpts().CPlusPlus) { + Diag(Tok, getLangOpts().CPlusPlus17 ? diag::warn_cxx14_compat_constexpr_if + : diag::ext_constexpr_if); + IsConstexpr = true; + ConsumeToken(); +} } else { if (Tok.is(tok::exclaim)) { NotLocation = ConsumeToken(); diff --git a/clang/test/Sema/constexpr.c b/clang/test/Sema/constexpr.c index 8286cd2107d2f2..a874fd64808404 100644 --- a/clang/test/Sema/constexpr.c +++ b/clang/test/Sema/constexpr.c @@ -357,3 +357,10 @@ void infsNaNs() { constexpr double db5 = LD_SNAN; // expected-error {{constexpr initializer evaluates to nan which is not exactly representable in type 'const double'}} constexpr double db6 = INF; } + +void constexprif() { + if constexpr (300) {} //expected-error {{expected '(' after 'if'}} +} +void constevalif() { + if consteval (300) {} //expected-error {{expected '(' after 'if'}} +} ___ 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] 007ad83 - Revert "[llvm][ARM]Add widen global arrays pass (#107120)"
Author: Nashe Mncube Date: 2024-10-17T13:35:23+01:00 New Revision: 007ad8343672de5161772c0873f87d00759fd82c URL: https://github.com/llvm/llvm-project/commit/007ad8343672de5161772c0873f87d00759fd82c DIFF: https://github.com/llvm/llvm-project/commit/007ad8343672de5161772c0873f87d00759fd82c.diff LOG: Revert "[llvm][ARM]Add widen global arrays pass (#107120)" This reverts commit ab90d2793cf56758a91f7a7ae027850af2455d3e. Added: Modified: llvm/include/llvm/Analysis/TargetTransformInfo.h llvm/include/llvm/Analysis/TargetTransformInfoImpl.h llvm/lib/Analysis/TargetTransformInfo.cpp llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp llvm/lib/Target/ARM/ARMTargetTransformInfo.h llvm/lib/Transforms/IPO/GlobalOpt.cpp Removed: llvm/test/Transforms/GlobalOpt/ARM/arm-widen-dest-non-array.ll llvm/test/Transforms/GlobalOpt/ARM/arm-widen-global-dest.ll llvm/test/Transforms/GlobalOpt/ARM/arm-widen-non-byte-array.ll llvm/test/Transforms/GlobalOpt/ARM/arm-widen-non-const-global.ll llvm/test/Transforms/GlobalOpt/ARM/arm-widen-string-multi-use.ll llvm/test/Transforms/GlobalOpt/ARM/arm-widen-strings-1.ll llvm/test/Transforms/GlobalOpt/ARM/arm-widen-strings-2.ll llvm/test/Transforms/GlobalOpt/ARM/arm-widen-strings-lengths-dont-match.ll llvm/test/Transforms/GlobalOpt/ARM/arm-widen-strings-more-than-64-bytes.ll llvm/test/Transforms/GlobalOpt/ARM/arm-widen-strings-ptrtoint.ll llvm/test/Transforms/GlobalOpt/ARM/arm-widen-strings-struct-test.ll llvm/test/Transforms/GlobalOpt/ARM/arm-widen-strings-volatile.ll diff --git a/llvm/include/llvm/Analysis/TargetTransformInfo.h b/llvm/include/llvm/Analysis/TargetTransformInfo.h index 0dc513d8e65b76..0459941fe05cdc 100644 --- a/llvm/include/llvm/Analysis/TargetTransformInfo.h +++ b/llvm/include/llvm/Analysis/TargetTransformInfo.h @@ -1819,10 +1819,6 @@ class TargetTransformInfo { /// \return The maximum number of function arguments the target supports. unsigned getMaxNumArgs() const; - /// \return For an array of given Size, return alignment boundary to - /// pad to. Default is no padding. - unsigned getNumBytesToPadGlobalArray(unsigned Size, Type *ArrayType) const; - /// @} private: @@ -2229,8 +2225,6 @@ class TargetTransformInfo::Concept { getVPLegalizationStrategy(const VPIntrinsic &PI) const = 0; virtual bool hasArmWideBranch(bool Thumb) const = 0; virtual unsigned getMaxNumArgs() const = 0; - virtual unsigned getNumBytesToPadGlobalArray(unsigned Size, - Type *ArrayType) const = 0; }; template @@ -3032,11 +3026,6 @@ class TargetTransformInfo::Model final : public TargetTransformInfo::Concept { unsigned getMaxNumArgs() const override { return Impl.getMaxNumArgs(); } - - unsigned getNumBytesToPadGlobalArray(unsigned Size, - Type *ArrayType) const override { -return Impl.getNumBytesToPadGlobalArray(Size, ArrayType); - } }; template diff --git a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h index 0b7792f89a05c4..dbdfb4d8cdfa32 100644 --- a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h +++ b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h @@ -1006,10 +1006,6 @@ class TargetTransformInfoImplBase { unsigned getMaxNumArgs() const { return UINT_MAX; } - unsigned getNumBytesToPadGlobalArray(unsigned Size, Type *ArrayType) const { -return 0; - } - protected: // Obtain the minimum required size to hold the value (without the sign) // In case of a vector it returns the min required size for one element. diff --git a/llvm/lib/Analysis/TargetTransformInfo.cpp b/llvm/lib/Analysis/TargetTransformInfo.cpp index 60704733637614..a47462b61e03b2 100644 --- a/llvm/lib/Analysis/TargetTransformInfo.cpp +++ b/llvm/lib/Analysis/TargetTransformInfo.cpp @@ -1383,12 +1383,6 @@ bool TargetTransformInfo::isVectorShiftByScalarCheap(Type *Ty) const { return TTIImpl->isVectorShiftByScalarCheap(Ty); } -unsigned -TargetTransformInfo::getNumBytesToPadGlobalArray(unsigned Size, - Type *ArrayType) const { - return TTIImpl->getNumBytesToPadGlobalArray(Size, ArrayType); -} - TargetTransformInfo::Concept::~Concept() = default; TargetIRAnalysis::TargetIRAnalysis() : TTICallback(&getDefaultTTI) {} diff --git a/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp b/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp index 9f6e5e5ab1421c..835ae98efb852d 100644 --- a/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp +++ b/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp @@ -56,10 +56,6 @@ static cl::opt AllowWLSLoops("allow-arm-wlsloops", cl::Hidden, cl::init(true), cl::desc("Enable the generation of WLS loops")); -static cl::opt UseWidenGlobalArrays( -"widen-g
[llvm-branch-commits] [clang] [clang] Reject if constexpr in C (#112685) (PR #112697)
https://github.com/AaronBallman approved this pull request. LGTM! https://github.com/llvm/llvm-project/pull/112697 ___ 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] GlobalISel: Fix combine duplicating atomic loads (PR #111730)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/111730 >From e6c0bf257510507bea11e9e8de2533cdd36cc13d Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Wed, 9 Oct 2024 22:05:48 +0400 Subject: [PATCH 1/2] GlobalISel: Fix combine duplicating atomic loads The sext_inreg (load) combine was not deleting the old load instruction, and it would never be deleted if volatile or atomic. --- .../lib/CodeGen/GlobalISel/CombinerHelper.cpp | 1 + .../AMDGPU/GlobalISel/atomic_load_flat.ll | 96 --- .../AMDGPU/GlobalISel/atomic_load_global.ll | 51 +++--- .../AMDGPU/GlobalISel/atomic_load_local_2.ll | 36 ++- ...lizer-combiner-sextload-from-sextinreg.mir | 2 - 5 files changed, 40 insertions(+), 146 deletions(-) diff --git a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp index f9b1621955c217..7bba493fba49fc 100644 --- a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp +++ b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp @@ -1110,6 +1110,7 @@ void CombinerHelper::applySextInRegOfLoad( Builder.buildLoadInstr(TargetOpcode::G_SEXTLOAD, MI.getOperand(0).getReg(), LoadDef->getPointerReg(), *NewMMO); MI.eraseFromParent(); + LoadDef->eraseFromParent(); } /// Return true if 'MI' is a load or a store that may be fold it's address diff --git a/llvm/test/CodeGen/AMDGPU/GlobalISel/atomic_load_flat.ll b/llvm/test/CodeGen/AMDGPU/GlobalISel/atomic_load_flat.ll index 817d1af9c226c8..83912b1e77db20 100644 --- a/llvm/test/CodeGen/AMDGPU/GlobalISel/atomic_load_flat.ll +++ b/llvm/test/CodeGen/AMDGPU/GlobalISel/atomic_load_flat.ll @@ -27,32 +27,12 @@ define i32 @atomic_load_flat_monotonic_i8_zext_to_i32(ptr %ptr) { } define i32 @atomic_load_flat_monotonic_i8_sext_to_i32(ptr %ptr) { -; GFX7-LABEL: atomic_load_flat_monotonic_i8_sext_to_i32: -; GFX7: ; %bb.0: -; GFX7-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) -; GFX7-NEXT:flat_load_sbyte v2, v[0:1] glc -; GFX7-NEXT:flat_load_ubyte v0, v[0:1] glc -; GFX7-NEXT:s_waitcnt vmcnt(0) lgkmcnt(0) -; GFX7-NEXT:v_mov_b32_e32 v0, v2 -; GFX7-NEXT:s_setpc_b64 s[30:31] -; -; GFX8-LABEL: atomic_load_flat_monotonic_i8_sext_to_i32: -; GFX8: ; %bb.0: -; GFX8-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) -; GFX8-NEXT:flat_load_sbyte v2, v[0:1] glc -; GFX8-NEXT:flat_load_ubyte v0, v[0:1] glc -; GFX8-NEXT:s_waitcnt vmcnt(0) lgkmcnt(0) -; GFX8-NEXT:v_mov_b32_e32 v0, v2 -; GFX8-NEXT:s_setpc_b64 s[30:31] -; -; GFX9-LABEL: atomic_load_flat_monotonic_i8_sext_to_i32: -; GFX9: ; %bb.0: -; GFX9-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) -; GFX9-NEXT:flat_load_sbyte v2, v[0:1] glc -; GFX9-NEXT:flat_load_ubyte v3, v[0:1] glc -; GFX9-NEXT:s_waitcnt vmcnt(0) lgkmcnt(0) -; GFX9-NEXT:v_mov_b32_e32 v0, v2 -; GFX9-NEXT:s_setpc_b64 s[30:31] +; GCN-LABEL: atomic_load_flat_monotonic_i8_sext_to_i32: +; GCN: ; %bb.0: +; GCN-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) +; GCN-NEXT:flat_load_sbyte v0, v[0:1] glc +; GCN-NEXT:s_waitcnt vmcnt(0) lgkmcnt(0) +; GCN-NEXT:s_setpc_b64 s[30:31] %load = load atomic i8, ptr %ptr monotonic, align 1 %ext = sext i8 %load to i32 ret i32 %ext @@ -71,32 +51,12 @@ define i16 @atomic_load_flat_monotonic_i8_zext_to_i16(ptr %ptr) { } define i16 @atomic_load_flat_monotonic_i8_sext_to_i16(ptr %ptr) { -; GFX7-LABEL: atomic_load_flat_monotonic_i8_sext_to_i16: -; GFX7: ; %bb.0: -; GFX7-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) -; GFX7-NEXT:flat_load_sbyte v2, v[0:1] glc -; GFX7-NEXT:flat_load_ubyte v0, v[0:1] glc -; GFX7-NEXT:s_waitcnt vmcnt(0) lgkmcnt(0) -; GFX7-NEXT:v_mov_b32_e32 v0, v2 -; GFX7-NEXT:s_setpc_b64 s[30:31] -; -; GFX8-LABEL: atomic_load_flat_monotonic_i8_sext_to_i16: -; GFX8: ; %bb.0: -; GFX8-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) -; GFX8-NEXT:flat_load_sbyte v2, v[0:1] glc -; GFX8-NEXT:flat_load_ubyte v0, v[0:1] glc -; GFX8-NEXT:s_waitcnt vmcnt(0) lgkmcnt(0) -; GFX8-NEXT:v_mov_b32_e32 v0, v2 -; GFX8-NEXT:s_setpc_b64 s[30:31] -; -; GFX9-LABEL: atomic_load_flat_monotonic_i8_sext_to_i16: -; GFX9: ; %bb.0: -; GFX9-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) -; GFX9-NEXT:flat_load_sbyte v2, v[0:1] glc -; GFX9-NEXT:flat_load_ubyte v3, v[0:1] glc -; GFX9-NEXT:s_waitcnt vmcnt(0) lgkmcnt(0) -; GFX9-NEXT:v_mov_b32_e32 v0, v2 -; GFX9-NEXT:s_setpc_b64 s[30:31] +; GCN-LABEL: atomic_load_flat_monotonic_i8_sext_to_i16: +; GCN: ; %bb.0: +; GCN-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) +; GCN-NEXT:flat_load_sbyte v0, v[0:1] glc +; GCN-NEXT:s_waitcnt vmcnt(0) lgkmcnt(0) +; GCN-NEXT:s_setpc_b64 s[30:31] %load = load atomic i8, ptr %ptr monotonic, align 1 %ext = sext i8 %load to i16 ret i16 %ext @@ -126,32 +86,12 @@ define i32 @atomic_load_flat_monotonic_i16_zext_to_i32(ptr %ptr) { } define i32 @atom
[llvm-branch-commits] [clang] [clang] Reject if constexpr in C (#112685) (PR #112697)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Mariya Podchishchaeva (Fznamznon) Changes Fixes https://github.com/llvm/llvm-project/issues/112587 --- Full diff: https://github.com/llvm/llvm-project/pull/112697.diff 2 Files Affected: - (modified) clang/lib/Parse/ParseStmt.cpp (+7-4) - (modified) clang/test/Sema/constexpr.c (+7) ``diff diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp index 22d38adc28ebe9..3ac1f0fa27f83f 100644 --- a/clang/lib/Parse/ParseStmt.cpp +++ b/clang/lib/Parse/ParseStmt.cpp @@ -1508,10 +1508,13 @@ StmtResult Parser::ParseIfStatement(SourceLocation *TrailingElseLoc) { SourceLocation ConstevalLoc; if (Tok.is(tok::kw_constexpr)) { -Diag(Tok, getLangOpts().CPlusPlus17 ? diag::warn_cxx14_compat_constexpr_if -: diag::ext_constexpr_if); -IsConstexpr = true; -ConsumeToken(); +// C23 supports constexpr keyword, but only for object definitions. +if (getLangOpts().CPlusPlus) { + Diag(Tok, getLangOpts().CPlusPlus17 ? diag::warn_cxx14_compat_constexpr_if + : diag::ext_constexpr_if); + IsConstexpr = true; + ConsumeToken(); +} } else { if (Tok.is(tok::exclaim)) { NotLocation = ConsumeToken(); diff --git a/clang/test/Sema/constexpr.c b/clang/test/Sema/constexpr.c index 8286cd2107d2f2..a874fd64808404 100644 --- a/clang/test/Sema/constexpr.c +++ b/clang/test/Sema/constexpr.c @@ -357,3 +357,10 @@ void infsNaNs() { constexpr double db5 = LD_SNAN; // expected-error {{constexpr initializer evaluates to nan which is not exactly representable in type 'const double'}} constexpr double db6 = INF; } + +void constexprif() { + if constexpr (300) {} //expected-error {{expected '(' after 'if'}} +} +void constevalif() { + if consteval (300) {} //expected-error {{expected '(' after 'if'}} +} `` https://github.com/llvm/llvm-project/pull/112697 ___ 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] Reject if constexpr in C (#112685) (PR #112697)
https://github.com/Fznamznon milestoned https://github.com/llvm/llvm-project/pull/112697 ___ 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] [libc] [libc][math][c23] Add log2f16 C23 math function (PR #106084)
https://github.com/overmighty updated https://github.com/llvm/llvm-project/pull/106084 >From 6d2abb503321d6564ce6333c366c2ab3d82b17a5 Mon Sep 17 00:00:00 2001 From: OverMighty Date: Mon, 26 Aug 2024 16:36:19 +0200 Subject: [PATCH 1/3] [libc][math][c23] Add log2f16 C23 math function Part of #95250. --- libc/config/gpu/entrypoints.txt | 1 + libc/config/linux/x86_64/entrypoints.txt | 1 + libc/docs/math/index.rst | 2 +- libc/spec/stdc.td | 1 + libc/src/math/CMakeLists.txt | 1 + libc/src/math/generic/CMakeLists.txt | 21 libc/src/math/generic/expxf16.h | 14 +++ libc/src/math/generic/log2f16.cpp | 147 ++ libc/src/math/log2f16.h | 21 libc/test/src/math/CMakeLists.txt | 11 ++ libc/test/src/math/log2f16_test.cpp | 40 ++ libc/test/src/math/smoke/CMakeLists.txt | 12 ++ libc/test/src/math/smoke/log2f16_test.cpp | 47 +++ 13 files changed, 318 insertions(+), 1 deletion(-) create mode 100644 libc/src/math/generic/log2f16.cpp create mode 100644 libc/src/math/log2f16.h create mode 100644 libc/test/src/math/log2f16_test.cpp create mode 100644 libc/test/src/math/smoke/log2f16_test.cpp diff --git a/libc/config/gpu/entrypoints.txt b/libc/config/gpu/entrypoints.txt index d9df737efea3d7..2cc54e8a4b970c 100644 --- a/libc/config/gpu/entrypoints.txt +++ b/libc/config/gpu/entrypoints.txt @@ -567,6 +567,7 @@ if(LIBC_TYPES_HAS_FLOAT16) libc.src.math.llogbf16 libc.src.math.llrintf16 libc.src.math.llroundf16 +libc.src.math.log2f16 libc.src.math.logbf16 libc.src.math.logf16 libc.src.math.lrintf16 diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt index 3d9d5a9e984c3d..06ea7bba81f345 100644 --- a/libc/config/linux/x86_64/entrypoints.txt +++ b/libc/config/linux/x86_64/entrypoints.txt @@ -660,6 +660,7 @@ if(LIBC_TYPES_HAS_FLOAT16) libc.src.math.llogbf16 libc.src.math.llrintf16 libc.src.math.llroundf16 +libc.src.math.log2f16 libc.src.math.logbf16 libc.src.math.logf16 libc.src.math.lrintf16 diff --git a/libc/docs/math/index.rst b/libc/docs/math/index.rst index a4c59190a01bcd..6591cbbdc15584 100644 --- a/libc/docs/math/index.rst +++ b/libc/docs/math/index.rst @@ -318,7 +318,7 @@ Higher Math Functions +---+--+-++--++++ | log1p | |check| | |check| || || 7.12.6.14 | F.10.3.14 | +---+--+-++--++++ -| log2 | |check| | |check| || || 7.12.6.15 | F.10.3.15 | +| log2 | |check| | |check| || |check| || 7.12.6.15 | F.10.3.15 | +---+--+-++--++++ | log2p1| | || || 7.12.6.16 | F.10.3.16 | +---+--+-++--++++ diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td index cc49835ac7e125..d2a073847503ef 100644 --- a/libc/spec/stdc.td +++ b/libc/spec/stdc.td @@ -648,6 +648,7 @@ def StdC : StandardSpec<"stdc"> { FunctionSpec<"log2", RetValSpec, [ArgSpec]>, FunctionSpec<"log2f", RetValSpec, [ArgSpec]>, + GuardedFunctionSpec<"log2f16", RetValSpec, [ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, FunctionSpec<"log", RetValSpec, [ArgSpec]>, FunctionSpec<"logf", RetValSpec, [ArgSpec]>, diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt index 9c6646cd658ed7..516bed499b1941 100644 --- a/libc/src/math/CMakeLists.txt +++ b/libc/src/math/CMakeLists.txt @@ -340,6 +340,7 @@ add_math_entrypoint_object(log1pf) add_math_entrypoint_object(log2) add_math_entrypoint_object(log2f) +add_math_entrypoint_object(log2f16) add_math_entrypoint_object(log) add_math_entrypoint_object(logf) diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt index b95672bc396878..a0b021228ce28a 100644 --- a/libc/src/math/generic/CMakeLists.txt +++ b/libc/src/math/generi
[llvm-branch-commits] [llvm] [CGData] Global Merge Functions (PR #112671)
https://github.com/kyulee-com updated https://github.com/llvm/llvm-project/pull/112671 >From 1601086634428b95d1a195e5ecb8f5b9d1f1709c Mon Sep 17 00:00:00 2001 From: Kyungwoo Lee Date: Fri, 30 Aug 2024 00:09:09 -0700 Subject: [PATCH] [CGData] Global Merge Functions --- llvm/include/llvm/CGData/CodeGenData.h| 11 + llvm/include/llvm/InitializePasses.h | 1 + llvm/include/llvm/LinkAllPasses.h | 1 + llvm/include/llvm/Passes/CodeGenPassBuilder.h | 1 + llvm/include/llvm/Transforms/IPO.h| 2 + .../Transforms/IPO/GlobalMergeFunctions.h | 77 ++ llvm/lib/CodeGen/TargetPassConfig.cpp | 3 + llvm/lib/LTO/LTO.cpp | 1 + llvm/lib/Transforms/IPO/CMakeLists.txt| 2 + .../Transforms/IPO/GlobalMergeFunctions.cpp | 687 ++ .../ThinLTO/AArch64/cgdata-merge-local.ll | 62 ++ .../test/ThinLTO/AArch64/cgdata-merge-read.ll | 82 +++ .../AArch64/cgdata-merge-two-rounds.ll| 68 ++ .../ThinLTO/AArch64/cgdata-merge-write.ll | 97 +++ llvm/tools/llvm-lto2/CMakeLists.txt | 1 + llvm/tools/llvm-lto2/llvm-lto2.cpp| 6 + 16 files changed, 1102 insertions(+) create mode 100644 llvm/include/llvm/Transforms/IPO/GlobalMergeFunctions.h create mode 100644 llvm/lib/Transforms/IPO/GlobalMergeFunctions.cpp create mode 100644 llvm/test/ThinLTO/AArch64/cgdata-merge-local.ll create mode 100644 llvm/test/ThinLTO/AArch64/cgdata-merge-read.ll create mode 100644 llvm/test/ThinLTO/AArch64/cgdata-merge-two-rounds.ll create mode 100644 llvm/test/ThinLTO/AArch64/cgdata-merge-write.ll diff --git a/llvm/include/llvm/CGData/CodeGenData.h b/llvm/include/llvm/CGData/CodeGenData.h index 5d7c74725ccef1..da0e412f2a0e03 100644 --- a/llvm/include/llvm/CGData/CodeGenData.h +++ b/llvm/include/llvm/CGData/CodeGenData.h @@ -145,6 +145,9 @@ class CodeGenData { const OutlinedHashTree *getOutlinedHashTree() { return PublishedHashTree.get(); } + const StableFunctionMap *getStableFunctionMap() { +return PublishedStableFunctionMap.get(); + } /// Returns true if we should write codegen data. bool emitCGData() { return EmitCGData; } @@ -169,10 +172,18 @@ inline bool hasOutlinedHashTree() { return CodeGenData::getInstance().hasOutlinedHashTree(); } +inline bool hasStableFunctionMap() { + return CodeGenData::getInstance().hasStableFunctionMap(); +} + inline const OutlinedHashTree *getOutlinedHashTree() { return CodeGenData::getInstance().getOutlinedHashTree(); } +inline const StableFunctionMap *getStableFunctionMap() { + return CodeGenData::getInstance().getStableFunctionMap(); +} + inline bool emitCGData() { return CodeGenData::getInstance().emitCGData(); } inline void diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h index 4352099d6dbb99..9aa36d5bb7f801 100644 --- a/llvm/include/llvm/InitializePasses.h +++ b/llvm/include/llvm/InitializePasses.h @@ -123,6 +123,7 @@ void initializeGCEmptyBasicBlocksPass(PassRegistry &); void initializeGCMachineCodeAnalysisPass(PassRegistry &); void initializeGCModuleInfoPass(PassRegistry &); void initializeGVNLegacyPassPass(PassRegistry &); +void initializeGlobalMergeFuncPass(PassRegistry &); void initializeGlobalMergePass(PassRegistry &); void initializeGlobalsAAWrapperPassPass(PassRegistry &); void initializeHardwareLoopsLegacyPass(PassRegistry &); diff --git a/llvm/include/llvm/LinkAllPasses.h b/llvm/include/llvm/LinkAllPasses.h index 92b59a66567c95..ea3609a2b4bc71 100644 --- a/llvm/include/llvm/LinkAllPasses.h +++ b/llvm/include/llvm/LinkAllPasses.h @@ -79,6 +79,7 @@ struct ForcePassLinking { (void)llvm::createDomOnlyViewerWrapperPassPass(); (void)llvm::createDomViewerWrapperPassPass(); (void)llvm::createAlwaysInlinerLegacyPass(); +(void)llvm::createGlobalMergeFuncPass(); (void)llvm::createGlobalsAAWrapperPass(); (void)llvm::createInstSimplifyLegacyPass(); (void)llvm::createInstructionCombiningPass(); diff --git a/llvm/include/llvm/Passes/CodeGenPassBuilder.h b/llvm/include/llvm/Passes/CodeGenPassBuilder.h index 13bc4700d87029..96b5b815132bc0 100644 --- a/llvm/include/llvm/Passes/CodeGenPassBuilder.h +++ b/llvm/include/llvm/Passes/CodeGenPassBuilder.h @@ -74,6 +74,7 @@ #include "llvm/Target/CGPassBuilderOption.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Transforms/CFGuard.h" +#include "llvm/Transforms/IPO/GlobalMergeFunctions.h" #include "llvm/Transforms/Scalar/ConstantHoisting.h" #include "llvm/Transforms/Scalar/LoopPassManager.h" #include "llvm/Transforms/Scalar/LoopStrengthReduce.h" diff --git a/llvm/include/llvm/Transforms/IPO.h b/llvm/include/llvm/Transforms/IPO.h index ee0e35aa618325..86a8654f56997c 100644 --- a/llvm/include/llvm/Transforms/IPO.h +++ b/llvm/include/llvm/Transforms/IPO.h @@ -55,6 +55,8 @@ enum class PassSummaryAction { Export, ///< Export information to summary. }; +Pass *createGlobalMergeFuncP
[llvm-branch-commits] [llvm][fatlto] Drop any CFI related instrumentation after emitting bitcode (PR #112788)
@@ -1629,6 +1629,10 @@ PassBuilder::buildFatLTODefaultPipeline(OptimizationLevel Level, bool ThinLTO, MPM.addPass(buildLTOPreLinkDefaultPipeline(Level)); MPM.addPass(EmbedBitcodePass(ThinLTO, EmitSummary)); + // If we're doing FatLTO w/ CFI enabled, we don't want the type tests in the + // object file. + MPM.addPass(LowerTypeTestsPass(nullptr, nullptr, true, true)); petrhosek wrote: This PR depends on #112787 which adds the fourth argument. https://github.com/llvm/llvm-project/pull/112788 ___ 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] [sanitizer] Add MemCpyAccessible (PR #112794)
@@ -219,6 +219,32 @@ static void StopStackDepotBackgroundThread() { static void StopStackDepotBackgroundThread() {} #endif +void MemCpyAccessible(void *dest, const void *src, uptr n) { + if (TryMemCpy(dest, src, n)) vitalybuka wrote: Not sure as well. On some examples fast pass 4x faster than page by page. https://github.com/llvm/llvm-project/pull/112794 ___ 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][fatlto] Drop any CFI related instrumentation after emitting bitcode (PR #112788)
@@ -1629,6 +1629,10 @@ PassBuilder::buildFatLTODefaultPipeline(OptimizationLevel Level, bool ThinLTO, MPM.addPass(buildLTOPreLinkDefaultPipeline(Level)); MPM.addPass(EmbedBitcodePass(ThinLTO, EmitSummary)); + // If we're doing FatLTO w/ CFI enabled, we don't want the type tests in the + // object file. + MPM.addPass(LowerTypeTestsPass(nullptr, nullptr, true, true)); ilovepi wrote: And apologies for not adding you on both reviews. I had thought I added you and Nikita to https://github.com/llvm/llvm-project/pull/112787, but it looks like I hadn't. https://github.com/llvm/llvm-project/pull/112788 ___ 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] [sanitizer] Add MemCpyAccessible (PR #112794)
@@ -219,6 +219,32 @@ static void StopStackDepotBackgroundThread() { static void StopStackDepotBackgroundThread() {} #endif +void MemCpyAccessible(void *dest, const void *src, uptr n) { + if (TryMemCpy(dest, src, n)) +return; + + const uptr page_size = GetPageSize(); + uptr b = reinterpret_cast(src); + uptr b_up = RoundUpTo(b, page_size); + + uptr e = reinterpret_cast(src) + n; + uptr e_down = RoundDownTo(e, page_size); + + auto copy_or_zero = [dest, src](uptr b, uptr e) { fmayer wrote: Don't reuse `b` and `e` in and outside of the lambda https://github.com/llvm/llvm-project/pull/112794 ___ 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] [sanitizer] Add MemCpyAccessible (PR #112794)
@@ -219,6 +219,32 @@ static void StopStackDepotBackgroundThread() { static void StopStackDepotBackgroundThread() {} #endif +void MemCpyAccessible(void *dest, const void *src, uptr n) { + if (TryMemCpy(dest, src, n)) fmayer wrote: I am not fully sure about this optimization. In the case where there are holes this makes it more expensive. Does the caller generally know that? https://github.com/llvm/llvm-project/pull/112794 ___ 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] [sanitizer] Add MemCpyAccessible (PR #112794)
@@ -273,6 +273,8 @@ bool IsAccessibleMemoryRange(uptr beg, uptr size); // Returns true if we can read a memory range starting at `src`, and copies // content into `dest`. bool TryMemCpy(void *dest, const void *src, uptr n); +// Copies accesible memory, and zero fill the rest. fmayer wrote: nit: typo https://github.com/llvm/llvm-project/pull/112794 ___ 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][fatlto] Drop any CFI related instrumentation after emitting bitcode (PR #112788)
@@ -1629,6 +1629,10 @@ PassBuilder::buildFatLTODefaultPipeline(OptimizationLevel Level, bool ThinLTO, MPM.addPass(buildLTOPreLinkDefaultPipeline(Level)); MPM.addPass(EmbedBitcodePass(ThinLTO, EmitSummary)); + // If we're doing FatLTO w/ CFI enabled, we don't want the type tests in the + // object file. + MPM.addPass(LowerTypeTestsPass(nullptr, nullptr, true, true)); ilovepi wrote: Agreed. I'm not super happy w/ the boolean either. The only reason its required is to avoid asserting for the new use case, but that also implies that assertion doesn't always hold, so I'm not sure if its really a good idea to keep it. https://github.com/llvm/llvm-project/pull/112788 ___ 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][fatlto] Drop any CFI related instrumentation after emitting bitcode (PR #112788)
@@ -1629,6 +1629,10 @@ PassBuilder::buildFatLTODefaultPipeline(OptimizationLevel Level, bool ThinLTO, MPM.addPass(buildLTOPreLinkDefaultPipeline(Level)); MPM.addPass(EmbedBitcodePass(ThinLTO, EmitSummary)); + // If we're doing FatLTO w/ CFI enabled, we don't want the type tests in the + // object file. + MPM.addPass(LowerTypeTestsPass(nullptr, nullptr, true, true)); pcc wrote: The assertion is to check that the code is only removing type test assumes (possibly involving a phi). So I wouldn't call the functionality that you're adding "always drop type tests". What you're adding is more like "drop type tests" and what's there already is "drop type test assumes". So maybe you can name the enumerators based on that. https://github.com/llvm/llvm-project/pull/112788 ___ 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] [lld] [llvm] [CGData][llvm-cgdata] Support for stable function map (PR #112664)
https://github.com/kyulee-com updated https://github.com/llvm/llvm-project/pull/112664 >From 09f1ec7730868a53cb566b0913e7952dfc15fa16 Mon Sep 17 00:00:00 2001 From: Kyungwoo Lee Date: Mon, 9 Sep 2024 19:38:05 -0700 Subject: [PATCH] [CGData][llvm-cgdata] Support for stable function map This introduces a new cgdata format for stable function maps. The raw data is embedded in the __llvm_merge section during compile time. This data can be read and merged using the llvm-cgdata tool, into an indexed cgdata file. Consequently, the tool is now capable of handling either outlined hash trees, stable function maps, or both, as they are orthogonal. --- lld/test/MachO/cgdata-generate.s | 6 +- llvm/docs/CommandGuide/llvm-cgdata.rst| 16 ++-- llvm/include/llvm/CGData/CodeGenData.h| 24 +- llvm/include/llvm/CGData/CodeGenData.inc | 12 ++- llvm/include/llvm/CGData/CodeGenDataReader.h | 29 ++- llvm/include/llvm/CGData/CodeGenDataWriter.h | 17 +++- llvm/lib/CGData/CodeGenData.cpp | 30 --- llvm/lib/CGData/CodeGenDataReader.cpp | 63 +- llvm/lib/CGData/CodeGenDataWriter.cpp | 30 ++- llvm/test/tools/llvm-cgdata/empty.test| 8 +- llvm/test/tools/llvm-cgdata/error.test| 13 +-- .../merge-combined-funcmap-hashtree.test | 66 +++ .../llvm-cgdata/merge-funcmap-archive.test| 83 +++ .../llvm-cgdata/merge-funcmap-concat.test | 78 + .../llvm-cgdata/merge-funcmap-double.test | 79 ++ .../llvm-cgdata/merge-funcmap-single.test | 36 ...chive.test => merge-hashtree-archive.test} | 8 +- ...concat.test => merge-hashtree-concat.test} | 6 +- ...double.test => merge-hashtree-double.test} | 8 +- ...single.test => merge-hashtree-single.test} | 4 +- llvm/tools/llvm-cgdata/llvm-cgdata.cpp| 48 --- 21 files changed, 577 insertions(+), 87 deletions(-) create mode 100644 llvm/test/tools/llvm-cgdata/merge-combined-funcmap-hashtree.test create mode 100644 llvm/test/tools/llvm-cgdata/merge-funcmap-archive.test create mode 100644 llvm/test/tools/llvm-cgdata/merge-funcmap-concat.test create mode 100644 llvm/test/tools/llvm-cgdata/merge-funcmap-double.test create mode 100644 llvm/test/tools/llvm-cgdata/merge-funcmap-single.test rename llvm/test/tools/llvm-cgdata/{merge-archive.test => merge-hashtree-archive.test} (91%) rename llvm/test/tools/llvm-cgdata/{merge-concat.test => merge-hashtree-concat.test} (93%) rename llvm/test/tools/llvm-cgdata/{merge-double.test => merge-hashtree-double.test} (90%) rename llvm/test/tools/llvm-cgdata/{merge-single.test => merge-hashtree-single.test} (92%) diff --git a/lld/test/MachO/cgdata-generate.s b/lld/test/MachO/cgdata-generate.s index 174df39d666c5d..f942ae07f64e0e 100644 --- a/lld/test/MachO/cgdata-generate.s +++ b/lld/test/MachO/cgdata-generate.s @@ -3,12 +3,12 @@ # RUN: rm -rf %t; split-file %s %t -# Synthesize raw cgdata without the header (24 byte) from the indexed cgdata. +# Synthesize raw cgdata without the header (32 byte) from the indexed cgdata. # RUN: llvm-cgdata --convert --format binary %t/raw-1.cgtext -o %t/raw-1.cgdata -# RUN: od -t x1 -j 24 -An %t/raw-1.cgdata | tr -d '\n\r\t' | sed 's/[ ][ ]*/ /g; s/^[ ]*//; s/[ ]*$//; s/[ ]/,0x/g; s/^/0x/' > %t/raw-1-bytes.txt +# RUN: od -t x1 -j 32 -An %t/raw-1.cgdata | tr -d '\n\r\t' | sed 's/[ ][ ]*/ /g; s/^[ ]*//; s/[ ]*$//; s/[ ]/,0x/g; s/^/0x/' > %t/raw-1-bytes.txt # RUN: sed "s//$(cat %t/raw-1-bytes.txt)/g" %t/merge-template.s > %t/merge-1.s # RUN: llvm-cgdata --convert --format binary %t/raw-2.cgtext -o %t/raw-2.cgdata -# RUN: od -t x1 -j 24 -An %t/raw-2.cgdata | tr -d '\n\r\t' | sed 's/[ ][ ]*/ /g; s/^[ ]*//; s/[ ]*$//; s/[ ]/,0x/g; s/^/0x/' > %t/raw-2-bytes.txt +# RUN: od -t x1 -j 32 -An %t/raw-2.cgdata | tr -d '\n\r\t' | sed 's/[ ][ ]*/ /g; s/^[ ]*//; s/[ ]*$//; s/[ ]/,0x/g; s/^/0x/' > %t/raw-2-bytes.txt # RUN: sed "s//$(cat %t/raw-2-bytes.txt)/g" %t/merge-template.s > %t/merge-2.s # RUN: llvm-mc -filetype obj -triple arm64-apple-darwin %t/merge-1.s -o %t/merge-1.o diff --git a/llvm/docs/CommandGuide/llvm-cgdata.rst b/llvm/docs/CommandGuide/llvm-cgdata.rst index f592e1508844ee..0670decd087e39 100644 --- a/llvm/docs/CommandGuide/llvm-cgdata.rst +++ b/llvm/docs/CommandGuide/llvm-cgdata.rst @@ -11,15 +11,13 @@ SYNOPSIS DESCRIPTION --- -The :program:llvm-cgdata utility parses raw codegen data embedded -in compiled binary files and merges them into a single .cgdata file. -It can also inspect and manipulate .cgdata files. -Currently, the tool supports saving and restoring outlined hash trees, -enabling global function outlining across modules, allowing for more -efficient function outlining in subsequent compilations. -The design is extensible, allowing for the incorporation of additional -codegen summaries and optimization techniques, such as global function -merging, in the futur
[llvm-branch-commits] [llvm] [CGData] Stable Function Map (PR #112662)
https://github.com/kyulee-com updated https://github.com/llvm/llvm-project/pull/112662 >From 060a23e39a68729859bb7b74e38586b0356e2ba6 Mon Sep 17 00:00:00 2001 From: Kyungwoo Lee Date: Sat, 7 Sep 2024 22:48:17 -0700 Subject: [PATCH] [CGData] Stable Function Map These define the main data structures to represent stable functions and group similar functions in a function map. Serialization is supported in a binary or yaml form. --- llvm/include/llvm/CGData/StableFunctionMap.h | 139 .../llvm/CGData/StableFunctionMapRecord.h | 68 ++ llvm/lib/CGData/CMakeLists.txt| 2 + llvm/lib/CGData/StableFunctionMap.cpp | 167 +++ llvm/lib/CGData/StableFunctionMapRecord.cpp | 202 ++ llvm/unittests/CGData/CMakeLists.txt | 2 + .../CGData/StableFunctionMapRecordTest.cpp| 131 .../CGData/StableFunctionMapTest.cpp | 146 + 8 files changed, 857 insertions(+) create mode 100644 llvm/include/llvm/CGData/StableFunctionMap.h create mode 100644 llvm/include/llvm/CGData/StableFunctionMapRecord.h create mode 100644 llvm/lib/CGData/StableFunctionMap.cpp create mode 100644 llvm/lib/CGData/StableFunctionMapRecord.cpp create mode 100644 llvm/unittests/CGData/StableFunctionMapRecordTest.cpp create mode 100644 llvm/unittests/CGData/StableFunctionMapTest.cpp diff --git a/llvm/include/llvm/CGData/StableFunctionMap.h b/llvm/include/llvm/CGData/StableFunctionMap.h new file mode 100644 index 00..ec205ef846f5c9 --- /dev/null +++ b/llvm/include/llvm/CGData/StableFunctionMap.h @@ -0,0 +1,139 @@ +//===- StableFunctionMap.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 +// +//===-===// +// +// TODO +// +//===-===// + +#ifndef LLVM_CGDATA_STABLEFUNCTIONMAP_H +#define LLVM_CGDATA_STABLEFUNCTIONMAP_H + +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/StableHashing.h" +#include "llvm/ADT/StringMap.h" +#include "llvm/IR/StructuralHash.h" +#include "llvm/ObjectYAML/YAML.h" +#include "llvm/Support/raw_ostream.h" + +#include +#include + +namespace llvm { + +using IndexPairHash = std::pair; +using IndexOperandHashVecType = SmallVector; + +/// A stable function is a function with a stable hash while tracking the +/// locations of ignored operands and their hashes. +struct StableFunction { + /// The combined stable hash of the function. + stable_hash Hash; + /// The name of the function. + std::string FunctionName; + /// The name of the module the function is in. + std::string ModuleName; + /// The number of instructions. + unsigned InstCount; + /// A vector of pairs of IndexPair and operand hash which was skipped. + IndexOperandHashVecType IndexOperandHashes; + + StableFunction(stable_hash Hash, const std::string FunctionName, + const std::string ModuleName, unsigned InstCount, + IndexOperandHashVecType &&IndexOperandHashes) + : Hash(Hash), FunctionName(FunctionName), ModuleName(ModuleName), +InstCount(InstCount), +IndexOperandHashes(std::move(IndexOperandHashes)) {} + StableFunction() = default; +}; + +/// An efficient form of StableFunction for fast look-up +struct StableFunctionEntry { + /// The combined stable hash of the function. + stable_hash Hash; + /// Id of the function name. + unsigned FunctionNameId; + /// Id of the module name. + unsigned ModuleNameId; + /// The number of instructions. + unsigned InstCount; + /// A map from an IndexPair to a stable_hash which was skipped. + std::unique_ptr IndexOperandHashMap; + + StableFunctionEntry( + stable_hash Hash, unsigned FunctionNameId, unsigned ModuleNameId, + unsigned InstCount, + std::unique_ptr IndexOperandHashMap) + : Hash(Hash), FunctionNameId(FunctionNameId), ModuleNameId(ModuleNameId), +InstCount(InstCount), +IndexOperandHashMap(std::move(IndexOperandHashMap)) {} +}; + +using HashFuncsMapType = +DenseMap>>; + +class StableFunctionMap { + /// A map from a stable_hash to a vector of functions with that hash. + HashFuncsMapType HashToFuncs; + /// A vector of strings to hold names. + SmallVector IdToName; + /// A map from StringRef (name) to an ID. + StringMap NameToId; + /// True if the function map is finalized with minimal content. + bool Finalized = false; + +public: + /// Get the HashToFuncs map for serialization. + const HashFuncsMapType &getFunctionMap() const { return HashToFuncs; } + + /// Get the NameToId vector for serialization. + const SmallVector getNames() const { return IdToName; } + + /// Get an existing ID associated with the given name or create a new ID
[llvm-branch-commits] [libc] [libc][math][c23] Add log10f16 C23 math function (PR #106091)
https://github.com/overmighty updated https://github.com/llvm/llvm-project/pull/106091 >From d4ff8e37305f98ebb140bfd5d6968c73dc10a1c4 Mon Sep 17 00:00:00 2001 From: OverMighty Date: Mon, 26 Aug 2024 17:23:01 +0200 Subject: [PATCH 1/2] [libc][math][c23] Add log10f16 C23 math function Part of #95250. --- libc/config/gpu/entrypoints.txt| 1 + libc/config/linux/x86_64/entrypoints.txt | 1 + libc/docs/math/index.rst | 2 +- libc/spec/stdc.td | 1 + libc/src/math/CMakeLists.txt | 1 + libc/src/math/generic/CMakeLists.txt | 21 +++ libc/src/math/generic/expxf16.h| 14 ++ libc/src/math/generic/log10f16.cpp | 163 + libc/src/math/log10f16.h | 21 +++ libc/test/src/math/CMakeLists.txt | 11 ++ libc/test/src/math/log10f16_test.cpp | 40 + libc/test/src/math/smoke/CMakeLists.txt| 12 ++ libc/test/src/math/smoke/log10f16_test.cpp | 47 ++ 13 files changed, 334 insertions(+), 1 deletion(-) create mode 100644 libc/src/math/generic/log10f16.cpp create mode 100644 libc/src/math/log10f16.h create mode 100644 libc/test/src/math/log10f16_test.cpp create mode 100644 libc/test/src/math/smoke/log10f16_test.cpp diff --git a/libc/config/gpu/entrypoints.txt b/libc/config/gpu/entrypoints.txt index 2cc54e8a4b970c..13bb88894297ca 100644 --- a/libc/config/gpu/entrypoints.txt +++ b/libc/config/gpu/entrypoints.txt @@ -567,6 +567,7 @@ if(LIBC_TYPES_HAS_FLOAT16) libc.src.math.llogbf16 libc.src.math.llrintf16 libc.src.math.llroundf16 +libc.src.math.log10f16 libc.src.math.log2f16 libc.src.math.logbf16 libc.src.math.logf16 diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt index 06ea7bba81f345..6ed6ad8c2400f3 100644 --- a/libc/config/linux/x86_64/entrypoints.txt +++ b/libc/config/linux/x86_64/entrypoints.txt @@ -660,6 +660,7 @@ if(LIBC_TYPES_HAS_FLOAT16) libc.src.math.llogbf16 libc.src.math.llrintf16 libc.src.math.llroundf16 +libc.src.math.log10f16 libc.src.math.log2f16 libc.src.math.logbf16 libc.src.math.logf16 diff --git a/libc/docs/math/index.rst b/libc/docs/math/index.rst index 6591cbbdc15584..88751e2453f2c8 100644 --- a/libc/docs/math/index.rst +++ b/libc/docs/math/index.rst @@ -312,7 +312,7 @@ Higher Math Functions +---+--+-++--++++ | log | |check| | |check| || |check| || 7.12.6.11 | F.10.3.11 | +---+--+-++--++++ -| log10 | |check| | |check| || || 7.12.6.12 | F.10.3.12 | +| log10 | |check| | |check| || |check| || 7.12.6.12 | F.10.3.12 | +---+--+-++--++++ | log10p1 | | || || 7.12.6.13 | F.10.3.13 | +---+--+-++--++++ diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td index d2a073847503ef..33bec2f71627e5 100644 --- a/libc/spec/stdc.td +++ b/libc/spec/stdc.td @@ -642,6 +642,7 @@ def StdC : StandardSpec<"stdc"> { FunctionSpec<"log10", RetValSpec, [ArgSpec]>, FunctionSpec<"log10f", RetValSpec, [ArgSpec]>, + GuardedFunctionSpec<"log10f16", RetValSpec, [ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, FunctionSpec<"log1p", RetValSpec, [ArgSpec]>, FunctionSpec<"log1pf", RetValSpec, [ArgSpec]>, diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt index 516bed499b1941..9239f029abf87a 100644 --- a/libc/src/math/CMakeLists.txt +++ b/libc/src/math/CMakeLists.txt @@ -334,6 +334,7 @@ add_math_entrypoint_object(ldexpf128) add_math_entrypoint_object(log10) add_math_entrypoint_object(log10f) +add_math_entrypoint_object(log10f16) add_math_entrypoint_object(log1p) add_math_entrypoint_object(log1pf) diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt index d7c7a3431d3d95..eb7e83611fcd2e 100644 --- a/libc/src/math/generic/CMakeLists.t
[llvm-branch-commits] [lld] [CGData][lld-macho] Add Global Merge Func Pass (PR #112674)
https://github.com/kyulee-com updated https://github.com/llvm/llvm-project/pull/112674 >From 6b0b6194a02209036e032a8941f8e5817b402318 Mon Sep 17 00:00:00 2001 From: Kyungwoo Lee Date: Wed, 16 Oct 2024 22:56:38 -0700 Subject: [PATCH] [CGData][lld-macho] Add Global Merge Func Pass --- lld/MachO/CMakeLists.txt | 2 + lld/MachO/Driver.cpp | 18 +- lld/MachO/InputSection.h | 1 + lld/MachO/LTO.cpp | 7 +++ lld/test/MachO/cgdata-generate-merge.s | 85 ++ 5 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 lld/test/MachO/cgdata-generate-merge.s diff --git a/lld/MachO/CMakeLists.txt b/lld/MachO/CMakeLists.txt index ecf6ce609e59f2..137fe4939b4457 100644 --- a/lld/MachO/CMakeLists.txt +++ b/lld/MachO/CMakeLists.txt @@ -41,9 +41,11 @@ add_lld_library(lldMachO BitReader BitWriter CGData + CodeGen Core DebugInfoDWARF Demangle + IPO LTO MC ObjCARCOpts diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp index ab4abb1fa97efc..59c24a06a2cb20 100644 --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -1326,7 +1326,8 @@ static void codegenDataGenerate() { TimeTraceScope timeScope("Generating codegen data"); OutlinedHashTreeRecord globalOutlineRecord; - for (ConcatInputSection *isec : inputSections) + StableFunctionMapRecord globalMergeRecord; + for (ConcatInputSection *isec : inputSections) { if (isec->getSegName() == segment_names::data && isec->getName() == section_names::outlinedHashTree) { // Read outlined hash tree from each section. @@ -1337,10 +1338,25 @@ static void codegenDataGenerate() { // Merge it to the global hash tree. globalOutlineRecord.merge(localOutlineRecord); } +if (isec->getSegName() == segment_names::data && +isec->getName() == section_names::functionmap) { + // Read stable functions from each section. + StableFunctionMapRecord localMergeRecord; + auto *data = isec->data.data(); + localMergeRecord.deserialize(data); + + // Merge it to the global function map. + globalMergeRecord.merge(localMergeRecord); +} + } + + globalMergeRecord.finalize(); CodeGenDataWriter Writer; if (!globalOutlineRecord.empty()) Writer.addRecord(globalOutlineRecord); + if (!globalMergeRecord.empty()) +Writer.addRecord(globalMergeRecord); std::error_code EC; auto fileName = config->codegenDataGeneratePath; diff --git a/lld/MachO/InputSection.h b/lld/MachO/InputSection.h index 7ef0e31066f372..b86520d36cda5b 100644 --- a/lld/MachO/InputSection.h +++ b/lld/MachO/InputSection.h @@ -339,6 +339,7 @@ constexpr const char const_[] = "__const"; constexpr const char lazySymbolPtr[] = "__la_symbol_ptr"; constexpr const char lazyBinding[] = "__lazy_binding"; constexpr const char literals[] = "__literals"; +constexpr const char functionmap[] = "__llvm_merge"; constexpr const char moduleInitFunc[] = "__mod_init_func"; constexpr const char moduleTermFunc[] = "__mod_term_func"; constexpr const char nonLazySymbolPtr[] = "__nl_symbol_ptr"; diff --git a/lld/MachO/LTO.cpp b/lld/MachO/LTO.cpp index 28f5290edb58e3..9bddf9a6445f6d 100644 --- a/lld/MachO/LTO.cpp +++ b/lld/MachO/LTO.cpp @@ -25,6 +25,7 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/Transforms/IPO.h" #include "llvm/Transforms/ObjCARC.h" using namespace lld; @@ -38,6 +39,8 @@ static std::string getThinLTOOutputFile(StringRef modulePath) { config->thinLTOPrefixReplaceNew); } +extern cl::opt EnableGlobalMergeFunc; + static lto::Config createConfig() { lto::Config c; c.Options = initTargetOptionsFromCodeGenFlags(); @@ -49,6 +52,10 @@ static lto::Config createConfig() { c.MAttrs = getMAttrs(); c.DiagHandler = diagnosticHandler; + c.PreCodeGenPassesHook = [](legacy::PassManager &pm) { +if (EnableGlobalMergeFunc) + pm.add(createGlobalMergeFuncPass()); + }; c.AlwaysEmitRegularLTOObj = !config->ltoObjPath.empty(); c.TimeTraceEnabled = config->timeTraceEnabled; diff --git a/lld/test/MachO/cgdata-generate-merge.s b/lld/test/MachO/cgdata-generate-merge.s new file mode 100644 index 00..3f7fb6777bc3cf --- /dev/null +++ b/lld/test/MachO/cgdata-generate-merge.s @@ -0,0 +1,85 @@ +# UNSUPPORTED: system-windows +# REQUIRES: aarch64 + +# RUN: rm -rf %t; split-file %s %t + +# Synthesize raw cgdata without the header (32 byte) from the indexed cgdata. +# RUN: llvm-cgdata --convert --format binary %t/raw-1.cgtext -o %t/raw-1.cgdata +# RUN: od -t x1 -j 32 -An %t/raw-1.cgdata | tr -d '\n\r\t' | sed 's/[ ][ ]*/ /g; s/^[ ]*//; s/[ ]*$//; s/[ ]/,0x/g; s/^/0x/' > %t/raw-1-bytes.txt +# RUN: sed "s//$(cat %t/raw-1-bytes.txt)/g" %t/merge-template.s > %t/merge-1.s +# RUN: llvm-cgdata --convert --format binary %t/raw-2.cgtext -o %t/raw-2.cgdata +# RUN: od -t x1 -j
[llvm-branch-commits] [libc] [libc][math][c23] Add sqrtf16 C23 math function (PR #112406)
https://github.com/overmighty updated https://github.com/llvm/llvm-project/pull/112406 >From 52c1c1bad3cd90d17b90082063bdad49fb0b5aa9 Mon Sep 17 00:00:00 2001 From: OverMighty Date: Mon, 26 Aug 2024 18:43:12 +0200 Subject: [PATCH] [libc][math][c23] Add sqrtf16 C23 math function Part of #95250. --- libc/config/gpu/entrypoints.txt | 1 + libc/config/linux/aarch64/entrypoints.txt | 1 + libc/config/linux/x86_64/entrypoints.txt | 1 + libc/docs/math/index.rst | 2 +- libc/spec/stdc.td | 1 + libc/src/__support/FPUtil/generic/sqrt.h | 3 ++- libc/src/math/CMakeLists.txt | 1 + libc/src/math/generic/CMakeLists.txt | 12 ++ libc/src/math/generic/sqrtf16.cpp | 20 libc/src/math/sqrtf16.h | 21 + libc/test/src/math/CMakeLists.txt | 11 + libc/test/src/math/smoke/CMakeLists.txt | 12 ++ libc/test/src/math/smoke/sqrtf16_test.cpp | 13 +++ libc/test/src/math/sqrtf16_test.cpp | 28 +++ 14 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 libc/src/math/generic/sqrtf16.cpp create mode 100644 libc/src/math/sqrtf16.h create mode 100644 libc/test/src/math/smoke/sqrtf16_test.cpp create mode 100644 libc/test/src/math/sqrtf16_test.cpp diff --git a/libc/config/gpu/entrypoints.txt b/libc/config/gpu/entrypoints.txt index 13bb88894297ca..38e9f2e685caed 100644 --- a/libc/config/gpu/entrypoints.txt +++ b/libc/config/gpu/entrypoints.txt @@ -590,6 +590,7 @@ if(LIBC_TYPES_HAS_FLOAT16) libc.src.math.setpayloadf16 libc.src.math.setpayloadsigf16 libc.src.math.sinhf16 +libc.src.math.sqrtf16 libc.src.math.tanhf16 libc.src.math.totalorderf16 libc.src.math.totalordermagf16 diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt index 885827d304efe3..71c6e874429fed 100644 --- a/libc/config/linux/aarch64/entrypoints.txt +++ b/libc/config/linux/aarch64/entrypoints.txt @@ -680,6 +680,7 @@ if(LIBC_TYPES_HAS_FLOAT16) libc.src.math.setpayloadf16 libc.src.math.setpayloadsigf16 libc.src.math.sinpif16 +libc.src.math.sqrtf16 libc.src.math.totalorderf16 libc.src.math.totalordermagf16 libc.src.math.truncf16 diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt index 6ed6ad8c2400f3..9bc63edf06f28c 100644 --- a/libc/config/linux/x86_64/entrypoints.txt +++ b/libc/config/linux/x86_64/entrypoints.txt @@ -684,6 +684,7 @@ if(LIBC_TYPES_HAS_FLOAT16) libc.src.math.setpayloadsigf16 libc.src.math.sinhf16 libc.src.math.sinpif16 +libc.src.math.sqrtf16 libc.src.math.tanhf16 libc.src.math.totalorderf16 libc.src.math.totalordermagf16 diff --git a/libc/docs/math/index.rst b/libc/docs/math/index.rst index 88751e2453f2c8..ce4df92393ce7f 100644 --- a/libc/docs/math/index.rst +++ b/libc/docs/math/index.rst @@ -344,7 +344,7 @@ Higher Math Functions +---+--+-++--++++ | sinpi | |check| | || |check| || 7.12.4.13 | F.10.1.13 | +---+--+-++--++++ -| sqrt | |check| | |check| | |check|| | |check|| 7.12.7.10 | F.10.4.10 | +| sqrt | |check| | |check| | |check|| |check| | |check|| 7.12.7.10 | F.10.4.10 | +---+--+-++--++++ | tan | |check| | |check| || || 7.12.4.7 | F.10.1.7 | +---+--+-++--++++ diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td index 33bec2f71627e5..d1ebc6ffb5821e 100644 --- a/libc/spec/stdc.td +++ b/libc/spec/stdc.td @@ -754,6 +754,7 @@ def StdC : StandardSpec<"stdc"> { FunctionSpec<"sqrt", RetValSpec, [ArgSpec]>, FunctionSpec<"sqrtf", RetValSpec, [ArgSpec]>, FunctionSpec<"sqrtl", RetValSpec, [ArgSpec]>, + GuardedFunctionSpec<"sqrtf16", RetValSpec, [ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, GuardedFunctionSpec<"sqrtf128", Re
[llvm-branch-commits] [sanitizer] Add TryMemCpy (PR #112668)
@@ -325,6 +325,44 @@ bool IsAccessibleMemoryRange(uptr beg, uptr size) { return true; } +bool TryMemCpy(void *dest, const void *src, uptr n) { + int sock_pair[2]; + if (pipe(sock_pair)) +return false; + + auto cleanup = at_scope_exit([&]() { +internal_close(sock_pair[0]); +internal_close(sock_pair[1]); + }); + + SetNonBlock(sock_pair[0]); fmayer wrote: Actually maybe not. Because we always read after writing, so there should always be space in the buffer for writing, and always be data for reading. But we need to handle EINTR. https://github.com/llvm/llvm-project/pull/112668 ___ 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] [CGData] Global Merge Functions (PR #112671)
https://github.com/kyulee-com updated https://github.com/llvm/llvm-project/pull/112671 >From ded5771bb4ff7c8fd5401b4efe0af988539a8162 Mon Sep 17 00:00:00 2001 From: Kyungwoo Lee Date: Fri, 30 Aug 2024 00:09:09 -0700 Subject: [PATCH] [CGData] Global Merge Functions --- llvm/include/llvm/CGData/CodeGenData.h| 11 + llvm/include/llvm/InitializePasses.h | 1 + llvm/include/llvm/LinkAllPasses.h | 1 + llvm/include/llvm/Passes/CodeGenPassBuilder.h | 1 + llvm/include/llvm/Transforms/IPO.h| 2 + .../Transforms/IPO/GlobalMergeFunctions.h | 77 ++ llvm/lib/CodeGen/TargetPassConfig.cpp | 3 + llvm/lib/LTO/LTO.cpp | 1 + llvm/lib/Transforms/IPO/CMakeLists.txt| 2 + .../Transforms/IPO/GlobalMergeFunctions.cpp | 687 ++ .../ThinLTO/AArch64/cgdata-merge-local.ll | 62 ++ .../test/ThinLTO/AArch64/cgdata-merge-read.ll | 82 +++ .../AArch64/cgdata-merge-two-rounds.ll| 68 ++ .../ThinLTO/AArch64/cgdata-merge-write.ll | 97 +++ llvm/tools/llvm-lto2/CMakeLists.txt | 1 + llvm/tools/llvm-lto2/llvm-lto2.cpp| 6 + 16 files changed, 1102 insertions(+) create mode 100644 llvm/include/llvm/Transforms/IPO/GlobalMergeFunctions.h create mode 100644 llvm/lib/Transforms/IPO/GlobalMergeFunctions.cpp create mode 100644 llvm/test/ThinLTO/AArch64/cgdata-merge-local.ll create mode 100644 llvm/test/ThinLTO/AArch64/cgdata-merge-read.ll create mode 100644 llvm/test/ThinLTO/AArch64/cgdata-merge-two-rounds.ll create mode 100644 llvm/test/ThinLTO/AArch64/cgdata-merge-write.ll diff --git a/llvm/include/llvm/CGData/CodeGenData.h b/llvm/include/llvm/CGData/CodeGenData.h index 5d7c74725ccef1..da0e412f2a0e03 100644 --- a/llvm/include/llvm/CGData/CodeGenData.h +++ b/llvm/include/llvm/CGData/CodeGenData.h @@ -145,6 +145,9 @@ class CodeGenData { const OutlinedHashTree *getOutlinedHashTree() { return PublishedHashTree.get(); } + const StableFunctionMap *getStableFunctionMap() { +return PublishedStableFunctionMap.get(); + } /// Returns true if we should write codegen data. bool emitCGData() { return EmitCGData; } @@ -169,10 +172,18 @@ inline bool hasOutlinedHashTree() { return CodeGenData::getInstance().hasOutlinedHashTree(); } +inline bool hasStableFunctionMap() { + return CodeGenData::getInstance().hasStableFunctionMap(); +} + inline const OutlinedHashTree *getOutlinedHashTree() { return CodeGenData::getInstance().getOutlinedHashTree(); } +inline const StableFunctionMap *getStableFunctionMap() { + return CodeGenData::getInstance().getStableFunctionMap(); +} + inline bool emitCGData() { return CodeGenData::getInstance().emitCGData(); } inline void diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h index 4352099d6dbb99..9aa36d5bb7f801 100644 --- a/llvm/include/llvm/InitializePasses.h +++ b/llvm/include/llvm/InitializePasses.h @@ -123,6 +123,7 @@ void initializeGCEmptyBasicBlocksPass(PassRegistry &); void initializeGCMachineCodeAnalysisPass(PassRegistry &); void initializeGCModuleInfoPass(PassRegistry &); void initializeGVNLegacyPassPass(PassRegistry &); +void initializeGlobalMergeFuncPass(PassRegistry &); void initializeGlobalMergePass(PassRegistry &); void initializeGlobalsAAWrapperPassPass(PassRegistry &); void initializeHardwareLoopsLegacyPass(PassRegistry &); diff --git a/llvm/include/llvm/LinkAllPasses.h b/llvm/include/llvm/LinkAllPasses.h index 92b59a66567c95..ea3609a2b4bc71 100644 --- a/llvm/include/llvm/LinkAllPasses.h +++ b/llvm/include/llvm/LinkAllPasses.h @@ -79,6 +79,7 @@ struct ForcePassLinking { (void)llvm::createDomOnlyViewerWrapperPassPass(); (void)llvm::createDomViewerWrapperPassPass(); (void)llvm::createAlwaysInlinerLegacyPass(); +(void)llvm::createGlobalMergeFuncPass(); (void)llvm::createGlobalsAAWrapperPass(); (void)llvm::createInstSimplifyLegacyPass(); (void)llvm::createInstructionCombiningPass(); diff --git a/llvm/include/llvm/Passes/CodeGenPassBuilder.h b/llvm/include/llvm/Passes/CodeGenPassBuilder.h index 13bc4700d87029..96b5b815132bc0 100644 --- a/llvm/include/llvm/Passes/CodeGenPassBuilder.h +++ b/llvm/include/llvm/Passes/CodeGenPassBuilder.h @@ -74,6 +74,7 @@ #include "llvm/Target/CGPassBuilderOption.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Transforms/CFGuard.h" +#include "llvm/Transforms/IPO/GlobalMergeFunctions.h" #include "llvm/Transforms/Scalar/ConstantHoisting.h" #include "llvm/Transforms/Scalar/LoopPassManager.h" #include "llvm/Transforms/Scalar/LoopStrengthReduce.h" diff --git a/llvm/include/llvm/Transforms/IPO.h b/llvm/include/llvm/Transforms/IPO.h index ee0e35aa618325..86a8654f56997c 100644 --- a/llvm/include/llvm/Transforms/IPO.h +++ b/llvm/include/llvm/Transforms/IPO.h @@ -55,6 +55,8 @@ enum class PassSummaryAction { Export, ///< Export information to summary. }; +Pass *createGlobalMergeFuncP
[llvm-branch-commits] [sanitizer] Add TryMemCpy (PR #112668)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/112668 ___ 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] [sanitizer] Add TryMemCpy (PR #112668)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/112668 ___ 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] [sanitizer] Add MemCpyAccessible (PR #112794)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/112794 ___ 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] [sanitizer] Add MemCpyAccessible (PR #112794)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/112794 ___ 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] [sanitizer] Add MemCpyAccessible (PR #112794)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/112794 ___ 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][fatlto] Drop any CFI related instrumentation after emitting bitcode (PR #112788)
@@ -1629,6 +1629,10 @@ PassBuilder::buildFatLTODefaultPipeline(OptimizationLevel Level, bool ThinLTO, MPM.addPass(buildLTOPreLinkDefaultPipeline(Level)); MPM.addPass(EmbedBitcodePass(ThinLTO, EmitSummary)); + // If we're doing FatLTO w/ CFI enabled, we don't want the type tests in the + // object file. + MPM.addPass(LowerTypeTestsPass(nullptr, nullptr, true, true)); pcc wrote: How does this build? The ctor only takes three arguments. https://github.com/llvm/llvm-project/pull/112788 ___ 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][fatlto] Drop any CFI related instrumentation after emitting bitcode (PR #112788)
@@ -1629,6 +1629,10 @@ PassBuilder::buildFatLTODefaultPipeline(OptimizationLevel Level, bool ThinLTO, MPM.addPass(buildLTOPreLinkDefaultPipeline(Level)); MPM.addPass(EmbedBitcodePass(ThinLTO, EmitSummary)); + // If we're doing FatLTO w/ CFI enabled, we don't want the type tests in the + // object file. + MPM.addPass(LowerTypeTestsPass(nullptr, nullptr, true, true)); pcc wrote: Oh I see, you have a dependent change that adds the argument. https://github.com/llvm/llvm-project/commit/68a064b39b86d69c02de09cda2f06f4b87c2e69a I'm not really a big fan of adding another bool argument like this because it makes the callers less clear, can you do something else like make the existing argument into an enum? https://github.com/llvm/llvm-project/pull/112788 ___ 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] [lld] [llvm] [CGData][llvm-cgdata] Support for stable function map (PR #112664)
https://github.com/kyulee-com updated https://github.com/llvm/llvm-project/pull/112664 >From 09f1ec7730868a53cb566b0913e7952dfc15fa16 Mon Sep 17 00:00:00 2001 From: Kyungwoo Lee Date: Mon, 9 Sep 2024 19:38:05 -0700 Subject: [PATCH] [CGData][llvm-cgdata] Support for stable function map This introduces a new cgdata format for stable function maps. The raw data is embedded in the __llvm_merge section during compile time. This data can be read and merged using the llvm-cgdata tool, into an indexed cgdata file. Consequently, the tool is now capable of handling either outlined hash trees, stable function maps, or both, as they are orthogonal. --- lld/test/MachO/cgdata-generate.s | 6 +- llvm/docs/CommandGuide/llvm-cgdata.rst| 16 ++-- llvm/include/llvm/CGData/CodeGenData.h| 24 +- llvm/include/llvm/CGData/CodeGenData.inc | 12 ++- llvm/include/llvm/CGData/CodeGenDataReader.h | 29 ++- llvm/include/llvm/CGData/CodeGenDataWriter.h | 17 +++- llvm/lib/CGData/CodeGenData.cpp | 30 --- llvm/lib/CGData/CodeGenDataReader.cpp | 63 +- llvm/lib/CGData/CodeGenDataWriter.cpp | 30 ++- llvm/test/tools/llvm-cgdata/empty.test| 8 +- llvm/test/tools/llvm-cgdata/error.test| 13 +-- .../merge-combined-funcmap-hashtree.test | 66 +++ .../llvm-cgdata/merge-funcmap-archive.test| 83 +++ .../llvm-cgdata/merge-funcmap-concat.test | 78 + .../llvm-cgdata/merge-funcmap-double.test | 79 ++ .../llvm-cgdata/merge-funcmap-single.test | 36 ...chive.test => merge-hashtree-archive.test} | 8 +- ...concat.test => merge-hashtree-concat.test} | 6 +- ...double.test => merge-hashtree-double.test} | 8 +- ...single.test => merge-hashtree-single.test} | 4 +- llvm/tools/llvm-cgdata/llvm-cgdata.cpp| 48 --- 21 files changed, 577 insertions(+), 87 deletions(-) create mode 100644 llvm/test/tools/llvm-cgdata/merge-combined-funcmap-hashtree.test create mode 100644 llvm/test/tools/llvm-cgdata/merge-funcmap-archive.test create mode 100644 llvm/test/tools/llvm-cgdata/merge-funcmap-concat.test create mode 100644 llvm/test/tools/llvm-cgdata/merge-funcmap-double.test create mode 100644 llvm/test/tools/llvm-cgdata/merge-funcmap-single.test rename llvm/test/tools/llvm-cgdata/{merge-archive.test => merge-hashtree-archive.test} (91%) rename llvm/test/tools/llvm-cgdata/{merge-concat.test => merge-hashtree-concat.test} (93%) rename llvm/test/tools/llvm-cgdata/{merge-double.test => merge-hashtree-double.test} (90%) rename llvm/test/tools/llvm-cgdata/{merge-single.test => merge-hashtree-single.test} (92%) diff --git a/lld/test/MachO/cgdata-generate.s b/lld/test/MachO/cgdata-generate.s index 174df39d666c5d..f942ae07f64e0e 100644 --- a/lld/test/MachO/cgdata-generate.s +++ b/lld/test/MachO/cgdata-generate.s @@ -3,12 +3,12 @@ # RUN: rm -rf %t; split-file %s %t -# Synthesize raw cgdata without the header (24 byte) from the indexed cgdata. +# Synthesize raw cgdata without the header (32 byte) from the indexed cgdata. # RUN: llvm-cgdata --convert --format binary %t/raw-1.cgtext -o %t/raw-1.cgdata -# RUN: od -t x1 -j 24 -An %t/raw-1.cgdata | tr -d '\n\r\t' | sed 's/[ ][ ]*/ /g; s/^[ ]*//; s/[ ]*$//; s/[ ]/,0x/g; s/^/0x/' > %t/raw-1-bytes.txt +# RUN: od -t x1 -j 32 -An %t/raw-1.cgdata | tr -d '\n\r\t' | sed 's/[ ][ ]*/ /g; s/^[ ]*//; s/[ ]*$//; s/[ ]/,0x/g; s/^/0x/' > %t/raw-1-bytes.txt # RUN: sed "s//$(cat %t/raw-1-bytes.txt)/g" %t/merge-template.s > %t/merge-1.s # RUN: llvm-cgdata --convert --format binary %t/raw-2.cgtext -o %t/raw-2.cgdata -# RUN: od -t x1 -j 24 -An %t/raw-2.cgdata | tr -d '\n\r\t' | sed 's/[ ][ ]*/ /g; s/^[ ]*//; s/[ ]*$//; s/[ ]/,0x/g; s/^/0x/' > %t/raw-2-bytes.txt +# RUN: od -t x1 -j 32 -An %t/raw-2.cgdata | tr -d '\n\r\t' | sed 's/[ ][ ]*/ /g; s/^[ ]*//; s/[ ]*$//; s/[ ]/,0x/g; s/^/0x/' > %t/raw-2-bytes.txt # RUN: sed "s//$(cat %t/raw-2-bytes.txt)/g" %t/merge-template.s > %t/merge-2.s # RUN: llvm-mc -filetype obj -triple arm64-apple-darwin %t/merge-1.s -o %t/merge-1.o diff --git a/llvm/docs/CommandGuide/llvm-cgdata.rst b/llvm/docs/CommandGuide/llvm-cgdata.rst index f592e1508844ee..0670decd087e39 100644 --- a/llvm/docs/CommandGuide/llvm-cgdata.rst +++ b/llvm/docs/CommandGuide/llvm-cgdata.rst @@ -11,15 +11,13 @@ SYNOPSIS DESCRIPTION --- -The :program:llvm-cgdata utility parses raw codegen data embedded -in compiled binary files and merges them into a single .cgdata file. -It can also inspect and manipulate .cgdata files. -Currently, the tool supports saving and restoring outlined hash trees, -enabling global function outlining across modules, allowing for more -efficient function outlining in subsequent compilations. -The design is extensible, allowing for the incorporation of additional -codegen summaries and optimization techniques, such as global function -merging, in the futur
[llvm-branch-commits] [llvm] [CGData] Global Merge Functions (PR #112671)
https://github.com/kyulee-com updated https://github.com/llvm/llvm-project/pull/112671 >From 584a2d7fdadf91838b7b305a1b09056fcb0e805f Mon Sep 17 00:00:00 2001 From: Kyungwoo Lee Date: Fri, 30 Aug 2024 00:09:09 -0700 Subject: [PATCH] [CGData] Global Merge Functions --- llvm/include/llvm/CGData/CodeGenData.h| 11 + llvm/include/llvm/InitializePasses.h | 1 + llvm/include/llvm/LinkAllPasses.h | 1 + llvm/include/llvm/Passes/CodeGenPassBuilder.h | 1 + llvm/include/llvm/Transforms/IPO.h| 2 + .../Transforms/IPO/GlobalMergeFunctions.h | 73 ++ llvm/lib/CodeGen/TargetPassConfig.cpp | 3 + llvm/lib/LTO/LTO.cpp | 1 + llvm/lib/Transforms/IPO/CMakeLists.txt| 2 + .../Transforms/IPO/GlobalMergeFunctions.cpp | 666 ++ .../ThinLTO/AArch64/cgdata-merge-local.ll | 62 ++ .../test/ThinLTO/AArch64/cgdata-merge-read.ll | 82 +++ .../AArch64/cgdata-merge-two-rounds.ll| 68 ++ .../ThinLTO/AArch64/cgdata-merge-write.ll | 97 +++ llvm/tools/llvm-lto2/CMakeLists.txt | 1 + llvm/tools/llvm-lto2/llvm-lto2.cpp| 6 + 16 files changed, 1077 insertions(+) create mode 100644 llvm/include/llvm/Transforms/IPO/GlobalMergeFunctions.h create mode 100644 llvm/lib/Transforms/IPO/GlobalMergeFunctions.cpp create mode 100644 llvm/test/ThinLTO/AArch64/cgdata-merge-local.ll create mode 100644 llvm/test/ThinLTO/AArch64/cgdata-merge-read.ll create mode 100644 llvm/test/ThinLTO/AArch64/cgdata-merge-two-rounds.ll create mode 100644 llvm/test/ThinLTO/AArch64/cgdata-merge-write.ll diff --git a/llvm/include/llvm/CGData/CodeGenData.h b/llvm/include/llvm/CGData/CodeGenData.h index 5d7c74725ccef1..da0e412f2a0e03 100644 --- a/llvm/include/llvm/CGData/CodeGenData.h +++ b/llvm/include/llvm/CGData/CodeGenData.h @@ -145,6 +145,9 @@ class CodeGenData { const OutlinedHashTree *getOutlinedHashTree() { return PublishedHashTree.get(); } + const StableFunctionMap *getStableFunctionMap() { +return PublishedStableFunctionMap.get(); + } /// Returns true if we should write codegen data. bool emitCGData() { return EmitCGData; } @@ -169,10 +172,18 @@ inline bool hasOutlinedHashTree() { return CodeGenData::getInstance().hasOutlinedHashTree(); } +inline bool hasStableFunctionMap() { + return CodeGenData::getInstance().hasStableFunctionMap(); +} + inline const OutlinedHashTree *getOutlinedHashTree() { return CodeGenData::getInstance().getOutlinedHashTree(); } +inline const StableFunctionMap *getStableFunctionMap() { + return CodeGenData::getInstance().getStableFunctionMap(); +} + inline bool emitCGData() { return CodeGenData::getInstance().emitCGData(); } inline void diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h index 4352099d6dbb99..9aa36d5bb7f801 100644 --- a/llvm/include/llvm/InitializePasses.h +++ b/llvm/include/llvm/InitializePasses.h @@ -123,6 +123,7 @@ void initializeGCEmptyBasicBlocksPass(PassRegistry &); void initializeGCMachineCodeAnalysisPass(PassRegistry &); void initializeGCModuleInfoPass(PassRegistry &); void initializeGVNLegacyPassPass(PassRegistry &); +void initializeGlobalMergeFuncPass(PassRegistry &); void initializeGlobalMergePass(PassRegistry &); void initializeGlobalsAAWrapperPassPass(PassRegistry &); void initializeHardwareLoopsLegacyPass(PassRegistry &); diff --git a/llvm/include/llvm/LinkAllPasses.h b/llvm/include/llvm/LinkAllPasses.h index 92b59a66567c95..ea3609a2b4bc71 100644 --- a/llvm/include/llvm/LinkAllPasses.h +++ b/llvm/include/llvm/LinkAllPasses.h @@ -79,6 +79,7 @@ struct ForcePassLinking { (void)llvm::createDomOnlyViewerWrapperPassPass(); (void)llvm::createDomViewerWrapperPassPass(); (void)llvm::createAlwaysInlinerLegacyPass(); +(void)llvm::createGlobalMergeFuncPass(); (void)llvm::createGlobalsAAWrapperPass(); (void)llvm::createInstSimplifyLegacyPass(); (void)llvm::createInstructionCombiningPass(); diff --git a/llvm/include/llvm/Passes/CodeGenPassBuilder.h b/llvm/include/llvm/Passes/CodeGenPassBuilder.h index 13bc4700d87029..96b5b815132bc0 100644 --- a/llvm/include/llvm/Passes/CodeGenPassBuilder.h +++ b/llvm/include/llvm/Passes/CodeGenPassBuilder.h @@ -74,6 +74,7 @@ #include "llvm/Target/CGPassBuilderOption.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Transforms/CFGuard.h" +#include "llvm/Transforms/IPO/GlobalMergeFunctions.h" #include "llvm/Transforms/Scalar/ConstantHoisting.h" #include "llvm/Transforms/Scalar/LoopPassManager.h" #include "llvm/Transforms/Scalar/LoopStrengthReduce.h" diff --git a/llvm/include/llvm/Transforms/IPO.h b/llvm/include/llvm/Transforms/IPO.h index ee0e35aa618325..86a8654f56997c 100644 --- a/llvm/include/llvm/Transforms/IPO.h +++ b/llvm/include/llvm/Transforms/IPO.h @@ -55,6 +55,8 @@ enum class PassSummaryAction { Export, ///< Export information to summary. }; +Pass *createGlobalMergeFuncP
[llvm-branch-commits] [libc] [libc][math][c23] Add sqrtf16 C23 math function (PR #112406)
llvmbot wrote: @llvm/pr-subscribers-libc Author: OverMighty (overmighty) Changes Part of #95250. --- Full diff: https://github.com/llvm/llvm-project/pull/112406.diff 14 Files Affected: - (modified) libc/config/gpu/entrypoints.txt (+1) - (modified) libc/config/linux/aarch64/entrypoints.txt (+1) - (modified) libc/config/linux/x86_64/entrypoints.txt (+1) - (modified) libc/docs/math/index.rst (+1-1) - (modified) libc/spec/stdc.td (+1) - (modified) libc/src/__support/FPUtil/generic/sqrt.h (+2-1) - (modified) libc/src/math/CMakeLists.txt (+1) - (modified) libc/src/math/generic/CMakeLists.txt (+12) - (added) libc/src/math/generic/sqrtf16.cpp (+20) - (added) libc/src/math/sqrtf16.h (+21) - (modified) libc/test/src/math/CMakeLists.txt (+11) - (modified) libc/test/src/math/smoke/CMakeLists.txt (+12) - (added) libc/test/src/math/smoke/sqrtf16_test.cpp (+13) - (added) libc/test/src/math/sqrtf16_test.cpp (+28) ``diff diff --git a/libc/config/gpu/entrypoints.txt b/libc/config/gpu/entrypoints.txt index 13bb88894297ca..38e9f2e685caed 100644 --- a/libc/config/gpu/entrypoints.txt +++ b/libc/config/gpu/entrypoints.txt @@ -590,6 +590,7 @@ if(LIBC_TYPES_HAS_FLOAT16) libc.src.math.setpayloadf16 libc.src.math.setpayloadsigf16 libc.src.math.sinhf16 +libc.src.math.sqrtf16 libc.src.math.tanhf16 libc.src.math.totalorderf16 libc.src.math.totalordermagf16 diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt index 885827d304efe3..71c6e874429fed 100644 --- a/libc/config/linux/aarch64/entrypoints.txt +++ b/libc/config/linux/aarch64/entrypoints.txt @@ -680,6 +680,7 @@ if(LIBC_TYPES_HAS_FLOAT16) libc.src.math.setpayloadf16 libc.src.math.setpayloadsigf16 libc.src.math.sinpif16 +libc.src.math.sqrtf16 libc.src.math.totalorderf16 libc.src.math.totalordermagf16 libc.src.math.truncf16 diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt index 6ed6ad8c2400f3..9bc63edf06f28c 100644 --- a/libc/config/linux/x86_64/entrypoints.txt +++ b/libc/config/linux/x86_64/entrypoints.txt @@ -684,6 +684,7 @@ if(LIBC_TYPES_HAS_FLOAT16) libc.src.math.setpayloadsigf16 libc.src.math.sinhf16 libc.src.math.sinpif16 +libc.src.math.sqrtf16 libc.src.math.tanhf16 libc.src.math.totalorderf16 libc.src.math.totalordermagf16 diff --git a/libc/docs/math/index.rst b/libc/docs/math/index.rst index 88751e2453f2c8..ce4df92393ce7f 100644 --- a/libc/docs/math/index.rst +++ b/libc/docs/math/index.rst @@ -344,7 +344,7 @@ Higher Math Functions +---+--+-++--++++ | sinpi | |check| | || |check| || 7.12.4.13 | F.10.1.13 | +---+--+-++--++++ -| sqrt | |check| | |check| | |check|| | |check|| 7.12.7.10 | F.10.4.10 | +| sqrt | |check| | |check| | |check|| |check| | |check|| 7.12.7.10 | F.10.4.10 | +---+--+-++--++++ | tan | |check| | |check| || || 7.12.4.7 | F.10.1.7 | +---+--+-++--++++ diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td index 33bec2f71627e5..d1ebc6ffb5821e 100644 --- a/libc/spec/stdc.td +++ b/libc/spec/stdc.td @@ -754,6 +754,7 @@ def StdC : StandardSpec<"stdc"> { FunctionSpec<"sqrt", RetValSpec, [ArgSpec]>, FunctionSpec<"sqrtf", RetValSpec, [ArgSpec]>, FunctionSpec<"sqrtl", RetValSpec, [ArgSpec]>, + GuardedFunctionSpec<"sqrtf16", RetValSpec, [ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, GuardedFunctionSpec<"sqrtf128", RetValSpec, [ArgSpec], "LIBC_TYPES_HAS_FLOAT128">, FunctionSpec<"trunc", RetValSpec, [ArgSpec]>, diff --git a/libc/src/__support/FPUtil/generic/sqrt.h b/libc/src/__support/FPUtil/generic/sqrt.h index 01af4bb7c90092..497ebd145c6b42 100644 --- a/libc/src/__support/FPUtil/generic/sqrt.h +++ b/libc/src/__support/FPUtil/generic/sqrt.h @@ -139,7 +139,8 @@ sqrt(InType x) { for (InStorageType cur
[llvm-branch-commits] [libc] [libc][math][c23] Add sqrtf16 C23 math function (PR #112406)
https://github.com/lntue approved this pull request. https://github.com/llvm/llvm-project/pull/112406 ___ 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] [flang] [lld] [llvm] [Flang] LLVM_ENABLE_RUNTIMES=FortranRuntime (PR #110217)
@@ -24,7 +24,7 @@ list(INSERT CMAKE_MODULE_PATH 0 # We order libraries to mirror roughly how they are layered, except that compiler-rt can depend # on libc++, so we put it after. set(LLVM_DEFAULT_RUNTIMES "libc;libunwind;libcxxabi;pstl;libcxx;compiler-rt;openmp;offload") -set(LLVM_SUPPORTED_RUNTIMES "${LLVM_DEFAULT_RUNTIMES};llvm-libgcc") +set(LLVM_SUPPORTED_RUNTIMES "${LLVM_DEFAULT_RUNTIMES};llvm-libgcc;flang-rt") h-vetinari wrote: > flang is not part of the default build, so `LLVM_ENABLE_PROJECTS=all > LLVM_ENABLE_RUNTIMES=all` would yield an error. AFAIU there have been long-standing discussions to include flang into the default build, and this was mostly waiting for the `flang-new` -> `flang` rename. After I couldn't find an issue for this, I opened one: #112789 https://github.com/llvm/llvm-project/pull/110217 ___ 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][fatlto] Drop any CFI related instrumentation after emitting bitcode (PR #112788)
https://github.com/ilovepi created https://github.com/llvm/llvm-project/pull/112788 We want to support CFI instrumentation for the bitcode section, without miscompiling the object code portion of a FatLTO object. We can reuse the existing mechanisms in the LowerTypeTestsPass to do that, by just adding the pass to the FatLTO pipeline after the EmbedBitcodePass with the correct options set. Fixes #112053 ___ 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][fatlto] Drop any CFI related instrumentation after emitting bitcode (PR #112788)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Paul Kirth (ilovepi) Changes We want to support CFI instrumentation for the bitcode section, without miscompiling the object code portion of a FatLTO object. We can reuse the existing mechanisms in the LowerTypeTestsPass to do that, by just adding the pass to the FatLTO pipeline after the EmbedBitcodePass with the correct options set. Fixes #112053 --- Full diff: https://github.com/llvm/llvm-project/pull/112788.diff 2 Files Affected: - (added) clang/test/CodeGen/fat-lto-objects-cfi.cpp (+46) - (modified) llvm/lib/Passes/PassBuilderPipelines.cpp (+4) ``diff diff --git a/clang/test/CodeGen/fat-lto-objects-cfi.cpp b/clang/test/CodeGen/fat-lto-objects-cfi.cpp new file mode 100644 index 00..022e74fd9b6f22 --- /dev/null +++ b/clang/test/CodeGen/fat-lto-objects-cfi.cpp @@ -0,0 +1,46 @@ +// REQUIRES: x86-registered-target + +// RUN: %clangxx --target=x86_64-unknown-fuchsia -O2 -flto -ffat-lto-objects \ +// RUN: -fsanitize=cfi -fvisibility=hidden -S -emit-llvm -o - %s \ +// RUN: | FileCheck %s + +// CHECK: llvm.embedded.object +// CHECK-SAME: section ".llvm.lto" + +// CHECK-LABEL: define hidden void @foo +// CHECK: entry: +// CHECK-NEXT: %cmp14.not = icmp eq i64 %len, 0 +// CHECK-NEXT: br i1 %cmp14.not, label %for.end7, label %for.cond1.preheader.preheader +// CHECK: for.cond1.preheader.preheader:; preds = %entry +// CHECK-NEXT: %arrayidx.1 = getelementptr inbounds nuw i8, ptr %ptr, i64 4 +// CHECK-NEXT: br label %for.cond1.preheader + +// CHECK-NOT: @llvm.type.test + +// The code below is a reduced case from https://github.com/llvm/llvm-project/issues/112053 +#define __PRINTFLIKE(__fmt, __varargs) __attribute__((__format__(__printf__, __fmt, __varargs))) +typedef void func(void* arg, const char* fmt, ...) __PRINTFLIKE(2, 3); +typedef __SIZE_TYPE__ size_t; +typedef unsigned long uintptr_t; + +extern "C" +void foo(const void* ptr, size_t len, long disp_addr, + func* printf_func, void* printf_arg) { + uintptr_t address = (uintptr_t)ptr; + size_t count; + + for (count = 0; count < len; count += 16) { +union { + unsigned int buf[4]; + unsigned char cbuf[16]; +} u; +size_t s = 10; +size_t i; + +for (i = 0; i < s / 4; i++) { + u.buf[i] = ((const unsigned int*)address)[i]; + printf_func(printf_arg, "%08x ", static_cast(u.buf[i])); +} + } +} + diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp index 17710eb94b6ded..81ea6ac7dcdf18 100644 --- a/llvm/lib/Passes/PassBuilderPipelines.cpp +++ b/llvm/lib/Passes/PassBuilderPipelines.cpp @@ -1629,6 +1629,10 @@ PassBuilder::buildFatLTODefaultPipeline(OptimizationLevel Level, bool ThinLTO, MPM.addPass(buildLTOPreLinkDefaultPipeline(Level)); MPM.addPass(EmbedBitcodePass(ThinLTO, EmitSummary)); + // If we're doing FatLTO w/ CFI enabled, we don't want the type tests in the + // object file. + MPM.addPass(LowerTypeTestsPass(nullptr, nullptr, true, true)); + // Use the ThinLTO post-link pipeline with sample profiling if (ThinLTO && PGOOpt && PGOOpt->Action == PGOOptions::SampleUse) MPM.addPass(buildThinLTODefaultPipeline(Level, /*ImportSummary=*/nullptr)); `` https://github.com/llvm/llvm-project/pull/112788 ___ 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] [sanitizer] Add MemCpyAccessible (PR #112794)
llvmbot wrote: @llvm/pr-subscribers-compiler-rt-sanitizer Author: Vitaly Buka (vitalybuka) Changes A layer over `TryMemCpy` to copy only availible pages. --- Full diff: https://github.com/llvm/llvm-project/pull/112794.diff 3 Files Affected: - (modified) compiler-rt/lib/sanitizer_common/sanitizer_common.h (+2) - (modified) compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cpp (+26) - (modified) compiler-rt/lib/sanitizer_common/tests/sanitizer_posix_test.cpp (+28-6) ``diff diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.h b/compiler-rt/lib/sanitizer_common/sanitizer_common.h index 9b1e58f5e7a61d..a7b6a4033a5276 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.h @@ -273,6 +273,8 @@ bool IsAccessibleMemoryRange(uptr beg, uptr size); // Returns true if we can read a memory range starting at `src`, and copies // content into `dest`. bool TryMemCpy(void *dest, const void *src, uptr n); +// Copies accesible memory, and zero fill the rest. +void MemCpyAccessible(void *dest, const void *src, uptr n); // Error report formatting. const char *StripPathPrefix(const char *filepath, diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cpp index 684720963a8dcb..3ad5aaa0a7d4ab 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cpp @@ -219,6 +219,32 @@ static void StopStackDepotBackgroundThread() { static void StopStackDepotBackgroundThread() {} #endif +void MemCpyAccessible(void *dest, const void *src, uptr n) { + if (TryMemCpy(dest, src, n)) +return; + + const uptr page_size = GetPageSize(); + uptr b = reinterpret_cast(src); + uptr b_up = RoundUpTo(b, page_size); + + uptr e = reinterpret_cast(src) + n; + uptr e_down = RoundDownTo(e, page_size); + + auto copy_or_zero = [dest, src](uptr b, uptr e) { +uptr d = reinterpret_cast(dest) + (b - reinterpret_cast(src)); +if (!TryMemCpy(reinterpret_cast(d), reinterpret_cast(b), + e - b)) + internal_memset(reinterpret_cast(d), 0, e - b); + }; + + copy_or_zero(b, b_up); + + for (uptr p = b_up; p < e_down; p += page_size) +copy_or_zero(p, p + page_size); + + copy_or_zero(e_down, e); +} + } // namespace __sanitizer SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_sandbox_on_notify, diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_posix_test.cpp b/compiler-rt/lib/sanitizer_common/tests/sanitizer_posix_test.cpp index 03a841a6f438cb..5016b09c15307f 100644 --- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_posix_test.cpp +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_posix_test.cpp @@ -127,19 +127,41 @@ TEST(SanitizerCommon, TryMemCpyNull) { EXPECT_FALSE(TryMemCpy(dst.data(), nullptr, dst.size())); } -TEST(SanitizerCommon, TryMemCpyProtected) { +TEST(SanitizerCommon, MemCpyAccessible) { + const int page_num = 1000; const int page_size = GetPageSize(); - InternalMmapVector src(3 * page_size); + InternalMmapVector src(page_num * page_size); std::iota(src.begin(), src.end(), 123); std::vector dst; - // Protect the middle page. - mprotect(src.data() + page_size, page_size, PROT_NONE); + std::vector exp = {src.begin(), src.end()}; + + // Protect some pages. + for (int i = 7; i < page_num; i *= 2) { +mprotect(src.data() + i * page_size, page_size, PROT_NONE); +std::fill(exp.data() + i * page_size, exp.data() + (i + 1) * page_size, 0); + } dst.assign(src.size(), 0); EXPECT_FALSE(TryMemCpy(dst.data(), src.data(), dst.size())); - mprotect(src.data() + page_size, page_size, PROT_READ | PROT_WRITE); - EXPECT_TRUE(std::equal(dst.begin(), dst.end(), src.begin())); + // Full page aligned range with mprotect pages. + dst.assign(src.size(), 0); + MemCpyAccessible(dst.data(), src.data(), dst.size()); + EXPECT_TRUE(std::equal(dst.begin(), dst.end(), exp.begin())); + + // Misaligned range with mprotect pages. + size_t offb = 3; + size_t offe = 7; + dst.assign(src.size() - offb - offe, 0); + MemCpyAccessible(dst.data(), src.data() + offb, dst.size()); + EXPECT_TRUE(std::equal(dst.begin(), dst.end(), exp.begin() + offb)); + + // Misaligned range with ends in mprotect pages. + offb = 3 + 7 * page_size; + offe = 7 + 14 * page_size; + dst.assign(src.size() - offb - offe, 0); + MemCpyAccessible(dst.data(), src.data() + offb, dst.size()); + EXPECT_TRUE(std::equal(dst.begin(), dst.end(), exp.begin() + offb)); } } // namespace __sanitizer `` https://github.com/llvm/llvm-project/pull/112794 ___ 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] [sanitizer] Add MemCpyAccessible (PR #112794)
https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/112794 A layer over `TryMemCpy` to copy only availible pages. ___ 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] [sanitizer] Add MemCpyAccessible (PR #112794)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/112794 ___ 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] [sanitizer] Add MemCpyAccessible (PR #112794)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/112794 ___ 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][fatlto] Drop any CFI related instrumentation after emitting bitcode (PR #112788)
https://github.com/ilovepi updated https://github.com/llvm/llvm-project/pull/112788 ___ 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][fatlto] Drop any CFI related instrumentation after emitting bitcode (PR #112788)
https://github.com/ilovepi updated https://github.com/llvm/llvm-project/pull/112788 ___ 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] [lld] [CGData][lld-macho] Add Global Merge Func Pass (PR #112674)
https://github.com/kyulee-com updated https://github.com/llvm/llvm-project/pull/112674 >From ead1aee8eeb4046ec0641c09652cea726becd48a Mon Sep 17 00:00:00 2001 From: Kyungwoo Lee Date: Wed, 16 Oct 2024 22:56:38 -0700 Subject: [PATCH] [CGData][lld-macho] Add Global Merge Func Pass --- lld/MachO/CMakeLists.txt | 2 + lld/MachO/Driver.cpp | 18 +- lld/MachO/InputSection.h | 1 + lld/MachO/LTO.cpp | 7 +++ lld/test/MachO/cgdata-generate-merge.s | 85 ++ 5 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 lld/test/MachO/cgdata-generate-merge.s diff --git a/lld/MachO/CMakeLists.txt b/lld/MachO/CMakeLists.txt index ecf6ce609e59f2..137fe4939b4457 100644 --- a/lld/MachO/CMakeLists.txt +++ b/lld/MachO/CMakeLists.txt @@ -41,9 +41,11 @@ add_lld_library(lldMachO BitReader BitWriter CGData + CodeGen Core DebugInfoDWARF Demangle + IPO LTO MC ObjCARCOpts diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp index ab4abb1fa97efc..59c24a06a2cb20 100644 --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -1326,7 +1326,8 @@ static void codegenDataGenerate() { TimeTraceScope timeScope("Generating codegen data"); OutlinedHashTreeRecord globalOutlineRecord; - for (ConcatInputSection *isec : inputSections) + StableFunctionMapRecord globalMergeRecord; + for (ConcatInputSection *isec : inputSections) { if (isec->getSegName() == segment_names::data && isec->getName() == section_names::outlinedHashTree) { // Read outlined hash tree from each section. @@ -1337,10 +1338,25 @@ static void codegenDataGenerate() { // Merge it to the global hash tree. globalOutlineRecord.merge(localOutlineRecord); } +if (isec->getSegName() == segment_names::data && +isec->getName() == section_names::functionmap) { + // Read stable functions from each section. + StableFunctionMapRecord localMergeRecord; + auto *data = isec->data.data(); + localMergeRecord.deserialize(data); + + // Merge it to the global function map. + globalMergeRecord.merge(localMergeRecord); +} + } + + globalMergeRecord.finalize(); CodeGenDataWriter Writer; if (!globalOutlineRecord.empty()) Writer.addRecord(globalOutlineRecord); + if (!globalMergeRecord.empty()) +Writer.addRecord(globalMergeRecord); std::error_code EC; auto fileName = config->codegenDataGeneratePath; diff --git a/lld/MachO/InputSection.h b/lld/MachO/InputSection.h index 7ef0e31066f372..b86520d36cda5b 100644 --- a/lld/MachO/InputSection.h +++ b/lld/MachO/InputSection.h @@ -339,6 +339,7 @@ constexpr const char const_[] = "__const"; constexpr const char lazySymbolPtr[] = "__la_symbol_ptr"; constexpr const char lazyBinding[] = "__lazy_binding"; constexpr const char literals[] = "__literals"; +constexpr const char functionmap[] = "__llvm_merge"; constexpr const char moduleInitFunc[] = "__mod_init_func"; constexpr const char moduleTermFunc[] = "__mod_term_func"; constexpr const char nonLazySymbolPtr[] = "__nl_symbol_ptr"; diff --git a/lld/MachO/LTO.cpp b/lld/MachO/LTO.cpp index 28f5290edb58e3..9bddf9a6445f6d 100644 --- a/lld/MachO/LTO.cpp +++ b/lld/MachO/LTO.cpp @@ -25,6 +25,7 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/Transforms/IPO.h" #include "llvm/Transforms/ObjCARC.h" using namespace lld; @@ -38,6 +39,8 @@ static std::string getThinLTOOutputFile(StringRef modulePath) { config->thinLTOPrefixReplaceNew); } +extern cl::opt EnableGlobalMergeFunc; + static lto::Config createConfig() { lto::Config c; c.Options = initTargetOptionsFromCodeGenFlags(); @@ -49,6 +52,10 @@ static lto::Config createConfig() { c.MAttrs = getMAttrs(); c.DiagHandler = diagnosticHandler; + c.PreCodeGenPassesHook = [](legacy::PassManager &pm) { +if (EnableGlobalMergeFunc) + pm.add(createGlobalMergeFuncPass()); + }; c.AlwaysEmitRegularLTOObj = !config->ltoObjPath.empty(); c.TimeTraceEnabled = config->timeTraceEnabled; diff --git a/lld/test/MachO/cgdata-generate-merge.s b/lld/test/MachO/cgdata-generate-merge.s new file mode 100644 index 00..3f7fb6777bc3cf --- /dev/null +++ b/lld/test/MachO/cgdata-generate-merge.s @@ -0,0 +1,85 @@ +# UNSUPPORTED: system-windows +# REQUIRES: aarch64 + +# RUN: rm -rf %t; split-file %s %t + +# Synthesize raw cgdata without the header (32 byte) from the indexed cgdata. +# RUN: llvm-cgdata --convert --format binary %t/raw-1.cgtext -o %t/raw-1.cgdata +# RUN: od -t x1 -j 32 -An %t/raw-1.cgdata | tr -d '\n\r\t' | sed 's/[ ][ ]*/ /g; s/^[ ]*//; s/[ ]*$//; s/[ ]/,0x/g; s/^/0x/' > %t/raw-1-bytes.txt +# RUN: sed "s//$(cat %t/raw-1-bytes.txt)/g" %t/merge-template.s > %t/merge-1.s +# RUN: llvm-cgdata --convert --format binary %t/raw-2.cgtext -o %t/raw-2.cgdata +# RUN: od -t x1 -j
[llvm-branch-commits] [llvm] [llvm][fatlto] Drop any CFI related instrumentation after emitting bitcode (PR #112788)
https://github.com/ilovepi updated https://github.com/llvm/llvm-project/pull/112788 >From ad89d61e60bac57cf8c66a974d741377ebe1db30 Mon Sep 17 00:00:00 2001 From: Paul Kirth Date: Fri, 18 Oct 2024 01:59:26 + Subject: [PATCH] Use new enum in constructor Created using spr 1.3.4 --- llvm/lib/Passes/PassBuilderPipelines.cpp | 7 +-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp index aec79304ab5c3c..0585e83e59a9ab 100644 --- a/llvm/lib/Passes/PassBuilderPipelines.cpp +++ b/llvm/lib/Passes/PassBuilderPipelines.cpp @@ -1631,8 +1631,11 @@ PassBuilder::buildFatLTODefaultPipeline(OptimizationLevel Level, bool ThinLTO, MPM.addPass(EmbedBitcodePass(ThinLTO, EmitSummary)); // If we're doing FatLTO w/ CFI enabled, we don't want the type tests in the - // object file. - MPM.addPass(LowerTypeTestsPass(nullptr, nullptr, true, true)); + // object code, only in the bitcode section, so drop it before we run + // module optimization and generate machine code. If llvm.type.test() isn't in + // the IR, this won't do anything. + MPM.addPass( + LowerTypeTestsPass(nullptr, nullptr, lowertypetests::DropTestKind::All)); // Use the ThinLTO post-link pipeline with sample profiling if (ThinLTO && PGOOpt && PGOOpt->Action == PGOOptions::SampleUse) ___ 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] [libc] [libc][math][c23] Add logf16 C23 math function (PR #106072)
https://github.com/overmighty updated https://github.com/llvm/llvm-project/pull/106072 >From f011fa727e0974dc3ec69ecd8b5860008efa524d Mon Sep 17 00:00:00 2001 From: OverMighty Date: Mon, 26 Aug 2024 15:30:54 +0200 Subject: [PATCH 1/4] [libc][math][c23] Add logf16 C23 math function Part of #95250. --- libc/config/gpu/entrypoints.txt | 1 + libc/config/linux/x86_64/entrypoints.txt | 1 + libc/docs/math/index.rst | 2 +- libc/spec/stdc.td| 1 + libc/src/math/CMakeLists.txt | 1 + libc/src/math/generic/CMakeLists.txt | 22 libc/src/math/generic/expxf16.h | 26 libc/src/math/generic/logf16.cpp | 158 +++ libc/src/math/logf16.h | 21 +++ libc/test/UnitTest/FPMatcher.h | 13 ++ libc/test/src/math/CMakeLists.txt| 11 ++ libc/test/src/math/logf16_test.cpp | 40 ++ libc/test/src/math/smoke/CMakeLists.txt | 12 ++ libc/test/src/math/smoke/logf16_test.cpp | 47 +++ 14 files changed, 355 insertions(+), 1 deletion(-) create mode 100644 libc/src/math/generic/logf16.cpp create mode 100644 libc/src/math/logf16.h create mode 100644 libc/test/src/math/logf16_test.cpp create mode 100644 libc/test/src/math/smoke/logf16_test.cpp diff --git a/libc/config/gpu/entrypoints.txt b/libc/config/gpu/entrypoints.txt index d89093b2117c2d..d9df737efea3d7 100644 --- a/libc/config/gpu/entrypoints.txt +++ b/libc/config/gpu/entrypoints.txt @@ -568,6 +568,7 @@ if(LIBC_TYPES_HAS_FLOAT16) libc.src.math.llrintf16 libc.src.math.llroundf16 libc.src.math.logbf16 +libc.src.math.logf16 libc.src.math.lrintf16 libc.src.math.lroundf16 libc.src.math.modff16 diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt index 7314dbc660f3cb..3d9d5a9e984c3d 100644 --- a/libc/config/linux/x86_64/entrypoints.txt +++ b/libc/config/linux/x86_64/entrypoints.txt @@ -661,6 +661,7 @@ if(LIBC_TYPES_HAS_FLOAT16) libc.src.math.llrintf16 libc.src.math.llroundf16 libc.src.math.logbf16 +libc.src.math.logf16 libc.src.math.lrintf16 libc.src.math.lroundf16 libc.src.math.modff16 diff --git a/libc/docs/math/index.rst b/libc/docs/math/index.rst index 010377a90f6eac..a4c59190a01bcd 100644 --- a/libc/docs/math/index.rst +++ b/libc/docs/math/index.rst @@ -310,7 +310,7 @@ Higher Math Functions +---+--+-++--++++ | lgamma| | || || 7.12.8.3 | F.10.5.3 | +---+--+-++--++++ -| log | |check| | |check| || || 7.12.6.11 | F.10.3.11 | +| log | |check| | |check| || |check| || 7.12.6.11 | F.10.3.11 | +---+--+-++--++++ | log10 | |check| | |check| || || 7.12.6.12 | F.10.3.12 | +---+--+-++--++++ diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td index 196dab9f81b38e..cc49835ac7e125 100644 --- a/libc/spec/stdc.td +++ b/libc/spec/stdc.td @@ -651,6 +651,7 @@ def StdC : StandardSpec<"stdc"> { FunctionSpec<"log", RetValSpec, [ArgSpec]>, FunctionSpec<"logf", RetValSpec, [ArgSpec]>, + GuardedFunctionSpec<"logf16", RetValSpec, [ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, FunctionSpec<"logb", RetValSpec, [ArgSpec]>, FunctionSpec<"logbf", RetValSpec, [ArgSpec]>, diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt index 8427b550ab4c7c..9c6646cd658ed7 100644 --- a/libc/src/math/CMakeLists.txt +++ b/libc/src/math/CMakeLists.txt @@ -343,6 +343,7 @@ add_math_entrypoint_object(log2f) add_math_entrypoint_object(log) add_math_entrypoint_object(logf) +add_math_entrypoint_object(logf16) add_math_entrypoint_object(logb) add_math_entrypoint_object(logbf) diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt index 81b3e44db7923e..e7582c1939c760 100644 --- a/libc/src/math/generic/CMakeLis
[llvm-branch-commits] [clang] [flang] [lld] [llvm] [Flang] LLVM_ENABLE_RUNTIMES=FortranRuntime (PR #110217)
@@ -261,6 +263,7 @@ function(runtime_default_target) llvm_ExternalProject_Add(runtimes ${CMAKE_CURRENT_SOURCE_DIR}/../../runtimes DEPENDS ${ARG_DEPENDS} + ${enable_fortran} Meinersbur wrote: done https://github.com/llvm/llvm-project/pull/110217 ___ 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] Disable use of the counted_by attribute for whole struct pointers (#112636) (PR #112786)
https://github.com/bwendling created https://github.com/llvm/llvm-project/pull/112786 The whole struct is specificed in the __bdos. The calculation of the whole size of the structure can be done in two ways: 1) sizeof(struct S) + count * sizeof(typeof(fam)) 2) offsetof(struct S, fam) + count * sizeof(typeof(fam)) The first will add any remaining whitespace that might exist after allocation while the second method is more precise, but not quite expected from programmers. See [1] for a discussion of the topic. GCC isn't (currently) able to calculate __bdos on a pointer to the whole structure. Therefore, because of the above issue, we'll choose to match what GCC does for consistency's sake. [1] https://lore.kernel.org/lkml/ZvV6X5FPBBW7CO1f@archlinux/ >From 5ef6cde2a99774d3a2da8773cec45323098f7db1 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Thu, 17 Oct 2024 21:52:40 + Subject: [PATCH] [Clang] Disable use of the counted_by attribute for whole struct pointers (#112636) The whole struct is specificed in the __bdos. The calculation of the whole size of the structure can be done in two ways: 1) sizeof(struct S) + count * sizeof(typeof(fam)) 2) offsetof(struct S, fam) + count * sizeof(typeof(fam)) The first will add any remaining whitespace that might exist after allocation while the second method is more precise, but not quite expected from programmers. See [1] for a discussion of the topic. GCC isn't (currently) able to calculate __bdos on a pointer to the whole structure. Therefore, because of the above issue, we'll choose to match what GCC does for consistency's sake. [1] https://lore.kernel.org/lkml/ZvV6X5FPBBW7CO1f@archlinux/ Co-authored-by: Eli Friedman --- clang/lib/CodeGen/CGBuiltin.cpp | 45 +++-- clang/test/CodeGen/attr-counted-by.c | 253 +-- 2 files changed, 107 insertions(+), 191 deletions(-) diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 5639239359ab82..86d47054615e67 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -1001,6 +1001,24 @@ CodeGenFunction::emitFlexibleArrayMemberSize(const Expr *E, unsigned Type, // Can't find the field referenced by the "counted_by" attribute. return nullptr; + if (isa(Base)) +// The whole struct is specificed in the __bdos. The calculation of the +// whole size of the structure can be done in two ways: +// +// 1) sizeof(struct S) + count * sizeof(typeof(fam)) +// 2) offsetof(struct S, fam) + count * sizeof(typeof(fam)) +// +// The first will add additional padding after the end of the array, +// allocation while the second method is more precise, but not quite +// expected from programmers. See +// https://lore.kernel.org/lkml/ZvV6X5FPBBW7CO1f@archlinux/ for a +// discussion of the topic. +// +// GCC isn't (currently) able to calculate __bdos on a pointer to the whole +// structure. Therefore, because of the above issue, we'll choose to match +// what GCC does for consistency's sake. +return nullptr; + // Build a load of the counted_by field. bool IsSigned = CountedByFD->getType()->isSignedIntegerType(); Value *CountedByInst = EmitCountedByFieldExpr(Base, FAMDecl, CountedByFD); @@ -1031,32 +1049,9 @@ CodeGenFunction::emitFlexibleArrayMemberSize(const Expr *E, unsigned Type, CharUnits Size = Ctx.getTypeSizeInChars(ArrayTy->getElementType()); llvm::Constant *ElemSize = llvm::ConstantInt::get(ResType, Size.getQuantity(), IsSigned); - Value *FAMSize = + Value *Res = Builder.CreateMul(CountedByInst, ElemSize, "", !IsSigned, IsSigned); - FAMSize = Builder.CreateIntCast(FAMSize, ResType, IsSigned); - Value *Res = FAMSize; - - if (isa(Base)) { -// The whole struct is specificed in the __bdos. -const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(OuterRD); - -// Get the offset of the FAM. -llvm::Constant *FAMOffset = ConstantInt::get(ResType, Offset, IsSigned); -Value *OffsetAndFAMSize = -Builder.CreateAdd(FAMOffset, Res, "", !IsSigned, IsSigned); - -// Get the full size of the struct. -llvm::Constant *SizeofStruct = -ConstantInt::get(ResType, Layout.getSize().getQuantity(), IsSigned); - -// max(sizeof(struct s), -// offsetof(struct s, array) + p->count * sizeof(*p->array)) -Res = IsSigned - ? Builder.CreateBinaryIntrinsic(llvm::Intrinsic::smax, - OffsetAndFAMSize, SizeofStruct) - : Builder.CreateBinaryIntrinsic(llvm::Intrinsic::umax, - OffsetAndFAMSize, SizeofStruct); - } + Res = Builder.CreateIntCast(Res, ResType, IsSigned); // A negative \p IdxInst or \p CountedByInst means that the index lands // outside of the flexible array member. If that's the case, we want to diff --git a/clang/test/CodeGen/attr-counted-by.c b/cl
[llvm-branch-commits] [clang] [Clang] Disable use of the counted_by attribute for whole struct pointers (#112636) (PR #112786)
https://github.com/bwendling milestoned https://github.com/llvm/llvm-project/pull/112786 ___ 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] Disable use of the counted_by attribute for whole struct pointers (#112636) (PR #112786)
llvmbot wrote: @llvm/pr-subscribers-clang-codegen @llvm/pr-subscribers-clang Author: Bill Wendling (bwendling) Changes The whole struct is specificed in the __bdos. The calculation of the whole size of the structure can be done in two ways: 1) sizeof(struct S) + count * sizeof(typeof(fam)) 2) offsetof(struct S, fam) + count * sizeof(typeof(fam)) The first will add any remaining whitespace that might exist after allocation while the second method is more precise, but not quite expected from programmers. See [1] for a discussion of the topic. GCC isn't (currently) able to calculate __bdos on a pointer to the whole structure. Therefore, because of the above issue, we'll choose to match what GCC does for consistency's sake. [1] https://lore.kernel.org/lkml/ZvV6X5FPBBW7CO1f@archlinux/ --- Patch is 53.46 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/112786.diff 2 Files Affected: - (modified) clang/lib/CodeGen/CGBuiltin.cpp (+20-25) - (modified) clang/test/CodeGen/attr-counted-by.c (+87-166) ``diff diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 5639239359ab82..86d47054615e67 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -1001,6 +1001,24 @@ CodeGenFunction::emitFlexibleArrayMemberSize(const Expr *E, unsigned Type, // Can't find the field referenced by the "counted_by" attribute. return nullptr; + if (isa(Base)) +// The whole struct is specificed in the __bdos. The calculation of the +// whole size of the structure can be done in two ways: +// +// 1) sizeof(struct S) + count * sizeof(typeof(fam)) +// 2) offsetof(struct S, fam) + count * sizeof(typeof(fam)) +// +// The first will add additional padding after the end of the array, +// allocation while the second method is more precise, but not quite +// expected from programmers. See +// https://lore.kernel.org/lkml/ZvV6X5FPBBW7CO1f@archlinux/ for a +// discussion of the topic. +// +// GCC isn't (currently) able to calculate __bdos on a pointer to the whole +// structure. Therefore, because of the above issue, we'll choose to match +// what GCC does for consistency's sake. +return nullptr; + // Build a load of the counted_by field. bool IsSigned = CountedByFD->getType()->isSignedIntegerType(); Value *CountedByInst = EmitCountedByFieldExpr(Base, FAMDecl, CountedByFD); @@ -1031,32 +1049,9 @@ CodeGenFunction::emitFlexibleArrayMemberSize(const Expr *E, unsigned Type, CharUnits Size = Ctx.getTypeSizeInChars(ArrayTy->getElementType()); llvm::Constant *ElemSize = llvm::ConstantInt::get(ResType, Size.getQuantity(), IsSigned); - Value *FAMSize = + Value *Res = Builder.CreateMul(CountedByInst, ElemSize, "", !IsSigned, IsSigned); - FAMSize = Builder.CreateIntCast(FAMSize, ResType, IsSigned); - Value *Res = FAMSize; - - if (isa(Base)) { -// The whole struct is specificed in the __bdos. -const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(OuterRD); - -// Get the offset of the FAM. -llvm::Constant *FAMOffset = ConstantInt::get(ResType, Offset, IsSigned); -Value *OffsetAndFAMSize = -Builder.CreateAdd(FAMOffset, Res, "", !IsSigned, IsSigned); - -// Get the full size of the struct. -llvm::Constant *SizeofStruct = -ConstantInt::get(ResType, Layout.getSize().getQuantity(), IsSigned); - -// max(sizeof(struct s), -// offsetof(struct s, array) + p->count * sizeof(*p->array)) -Res = IsSigned - ? Builder.CreateBinaryIntrinsic(llvm::Intrinsic::smax, - OffsetAndFAMSize, SizeofStruct) - : Builder.CreateBinaryIntrinsic(llvm::Intrinsic::umax, - OffsetAndFAMSize, SizeofStruct); - } + Res = Builder.CreateIntCast(Res, ResType, IsSigned); // A negative \p IdxInst or \p CountedByInst means that the index lands // outside of the flexible array member. If that's the case, we want to diff --git a/clang/test/CodeGen/attr-counted-by.c b/clang/test/CodeGen/attr-counted-by.c index 322ef2d0f7db16..65e6c042730b47 100644 --- a/clang/test/CodeGen/attr-counted-by.c +++ b/clang/test/CodeGen/attr-counted-by.c @@ -66,7 +66,7 @@ struct anon_struct { // SANITIZE-WITH-ATTR-NEXT:[[TMP1:%.*]] = icmp ult i64 [[IDXPROM]], [[TMP0]], !nosanitize [[META2]] // SANITIZE-WITH-ATTR-NEXT:br i1 [[TMP1]], label [[CONT3:%.*]], label [[HANDLER_OUT_OF_BOUNDS:%.*]], !prof [[PROF3:![0-9]+]], !nosanitize [[META2]] // SANITIZE-WITH-ATTR: handler.out_of_bounds: -// SANITIZE-WITH-ATTR-NEXT:tail call void @__ubsan_handle_out_of_bounds_abort(ptr nonnull @[[GLOB1:[0-9]+]], i64 [[IDXPROM]]) #[[ATTR10:[0-9]+]], !nosanitize [[META2]] +// SANITIZE-WITH-ATTR-NEXT:tail call void @__ubsan_handle_out_of_bounds_abort(ptr nonnull @[[GLOB1:[0-9]+]], i64 [
[llvm-branch-commits] [clang] [Clang] Disable use of the counted_by attribute for whole struct pointers (#112636) (PR #112786)
https://github.com/bwendling edited https://github.com/llvm/llvm-project/pull/112786 ___ 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] [Coverage] Make additional counters available for BranchRegion. NFC. (PR #112730)
https://github.com/chapuni edited https://github.com/llvm/llvm-project/pull/112730 ___ 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] [lsan] Process non-suspended threads (PR #112807)
https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/112807 For such threads we have no registers, so no exact stack range, and no guaranties that stack is mapped at all. To avoid crashes on unmapped memory, `MemCpyAccessible` copies intersting range into temporarily buffer, and we search for pointers there. ___ 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] [lsan] Process non-suspended threads (PR #112807)
llvmbot wrote: @llvm/pr-subscribers-compiler-rt-sanitizer Author: Vitaly Buka (vitalybuka) Changes For such threads we have no registers, so no exact stack range, and no guaranties that stack is mapped at all. To avoid crashes on unmapped memory, `MemCpyAccessible` copies intersting range into temporarily buffer, and we search for pointers there. --- Full diff: https://github.com/llvm/llvm-project/pull/112807.diff 2 Files Affected: - (modified) compiler-rt/lib/lsan/lsan_common.cpp (+40) - (modified) compiler-rt/lib/lsan/lsan_flags.inc (+2) ``diff diff --git a/compiler-rt/lib/lsan/lsan_common.cpp b/compiler-rt/lib/lsan/lsan_common.cpp index 9aed36b96ce929..05f1edae0f05c1 100644 --- a/compiler-rt/lib/lsan/lsan_common.cpp +++ b/compiler-rt/lib/lsan/lsan_common.cpp @@ -293,6 +293,27 @@ struct DirectMemoryAccessor { void Init(uptr begin, uptr end) {}; void *LoadPtr(uptr p) const { return *reinterpret_cast(p); } }; + +struct CopyLoader { + void Init(uptr begin, uptr end) { +buffer.clear(); +buffer.resize(end - begin); +offset = reinterpret_cast(buffer.data()) - begin; + +// Need a partial data? +MemCpyAccessible(buffer.data(), reinterpret_cast(begin), + buffer.size()); + }; + void *LoadPtr(uptr p) const { +CHECK_LE(p + offset + sizeof(void *), + reinterpret_cast(buffer.data() + buffer.size())); +return *reinterpret_cast(p + offset); + } + + private: + uptr offset; + InternalMmapVector buffer; +}; } // namespace // Scans the memory range, looking for byte patterns that point into allocator @@ -535,6 +556,7 @@ static void ProcessThread(tid_t os_id, uptr sp, static void ProcessThreads(SuspendedThreadsList const &suspended_threads, Frontier *frontier, tid_t caller_tid, uptr caller_sp) { + InternalMmapVector done_threads; InternalMmapVector registers; InternalMmapVector extra_ranges; for (uptr i = 0; i < suspended_threads.ThreadCount(); i++) { @@ -559,6 +581,24 @@ static void ProcessThreads(SuspendedThreadsList const &suspended_threads, DirectMemoryAccessor accessor; ProcessThread(os_id, sp, registers, extra_ranges, frontier, accessor); +done_threads.push_back(os_id); + } + + if (flags()->use_detached) { +CopyLoader accessor; +InternalMmapVector known_threads; +GetRunningThreadsLocked(&known_threads); +Sort(done_threads.data(), done_threads.size()); +for (tid_t os_id : known_threads) { + registers.clear(); + extra_ranges.clear(); + + uptr i = InternalLowerBound(done_threads, os_id); + if (i >= done_threads.size() || done_threads[i] != os_id) { +uptr sp = (os_id == caller_tid) ? caller_sp : 0; +ProcessThread(os_id, sp, registers, extra_ranges, frontier, accessor); + } +} } // Add pointers reachable from ThreadContexts diff --git a/compiler-rt/lib/lsan/lsan_flags.inc b/compiler-rt/lib/lsan/lsan_flags.inc index c97b021ba5c02f..09d759302fdd5d 100644 --- a/compiler-rt/lib/lsan/lsan_flags.inc +++ b/compiler-rt/lib/lsan/lsan_flags.inc @@ -41,6 +41,8 @@ LSAN_FLAG(bool, use_ld_allocations, true, LSAN_FLAG(bool, use_unaligned, false, "Consider unaligned pointers valid.") LSAN_FLAG(bool, use_poisoned, false, "Consider pointers found in poisoned memory to be valid.") +LSAN_FLAG(bool, use_detached, false, + "Scan threads even attaching to them failed.") LSAN_FLAG(bool, log_pointers, false, "Debug logging") LSAN_FLAG(bool, log_threads, false, "Debug logging") LSAN_FLAG(int, tries, 1, "Debug option to repeat leak checking multiple times") `` https://github.com/llvm/llvm-project/pull/112807 ___ 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] [lsan] Process non-suspended threads (PR #112807)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/112807 ___ 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] [lsan] Process non-suspended threads (PR #112807)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/112807 ___ 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] [lld] [CGData][lld-macho] Add Global Merge Func Pass (PR #112674)
https://github.com/kyulee-com updated https://github.com/llvm/llvm-project/pull/112674 >From 549cf5d3880450641c720a6bc1f3bddae272f902 Mon Sep 17 00:00:00 2001 From: Kyungwoo Lee Date: Wed, 16 Oct 2024 22:56:38 -0700 Subject: [PATCH] [CGData][lld-macho] Add Global Merge Func Pass --- lld/MachO/CMakeLists.txt | 2 + lld/MachO/Driver.cpp | 18 +- lld/MachO/InputSection.h | 1 + lld/MachO/LTO.cpp | 7 +++ lld/test/MachO/cgdata-generate-merge.s | 85 ++ 5 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 lld/test/MachO/cgdata-generate-merge.s diff --git a/lld/MachO/CMakeLists.txt b/lld/MachO/CMakeLists.txt index ecf6ce609e59f2..137fe4939b4457 100644 --- a/lld/MachO/CMakeLists.txt +++ b/lld/MachO/CMakeLists.txt @@ -41,9 +41,11 @@ add_lld_library(lldMachO BitReader BitWriter CGData + CodeGen Core DebugInfoDWARF Demangle + IPO LTO MC ObjCARCOpts diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp index ab4abb1fa97efc..59c24a06a2cb20 100644 --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -1326,7 +1326,8 @@ static void codegenDataGenerate() { TimeTraceScope timeScope("Generating codegen data"); OutlinedHashTreeRecord globalOutlineRecord; - for (ConcatInputSection *isec : inputSections) + StableFunctionMapRecord globalMergeRecord; + for (ConcatInputSection *isec : inputSections) { if (isec->getSegName() == segment_names::data && isec->getName() == section_names::outlinedHashTree) { // Read outlined hash tree from each section. @@ -1337,10 +1338,25 @@ static void codegenDataGenerate() { // Merge it to the global hash tree. globalOutlineRecord.merge(localOutlineRecord); } +if (isec->getSegName() == segment_names::data && +isec->getName() == section_names::functionmap) { + // Read stable functions from each section. + StableFunctionMapRecord localMergeRecord; + auto *data = isec->data.data(); + localMergeRecord.deserialize(data); + + // Merge it to the global function map. + globalMergeRecord.merge(localMergeRecord); +} + } + + globalMergeRecord.finalize(); CodeGenDataWriter Writer; if (!globalOutlineRecord.empty()) Writer.addRecord(globalOutlineRecord); + if (!globalMergeRecord.empty()) +Writer.addRecord(globalMergeRecord); std::error_code EC; auto fileName = config->codegenDataGeneratePath; diff --git a/lld/MachO/InputSection.h b/lld/MachO/InputSection.h index 7ef0e31066f372..b86520d36cda5b 100644 --- a/lld/MachO/InputSection.h +++ b/lld/MachO/InputSection.h @@ -339,6 +339,7 @@ constexpr const char const_[] = "__const"; constexpr const char lazySymbolPtr[] = "__la_symbol_ptr"; constexpr const char lazyBinding[] = "__lazy_binding"; constexpr const char literals[] = "__literals"; +constexpr const char functionmap[] = "__llvm_merge"; constexpr const char moduleInitFunc[] = "__mod_init_func"; constexpr const char moduleTermFunc[] = "__mod_term_func"; constexpr const char nonLazySymbolPtr[] = "__nl_symbol_ptr"; diff --git a/lld/MachO/LTO.cpp b/lld/MachO/LTO.cpp index 28f5290edb58e3..9bddf9a6445f6d 100644 --- a/lld/MachO/LTO.cpp +++ b/lld/MachO/LTO.cpp @@ -25,6 +25,7 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/Transforms/IPO.h" #include "llvm/Transforms/ObjCARC.h" using namespace lld; @@ -38,6 +39,8 @@ static std::string getThinLTOOutputFile(StringRef modulePath) { config->thinLTOPrefixReplaceNew); } +extern cl::opt EnableGlobalMergeFunc; + static lto::Config createConfig() { lto::Config c; c.Options = initTargetOptionsFromCodeGenFlags(); @@ -49,6 +52,10 @@ static lto::Config createConfig() { c.MAttrs = getMAttrs(); c.DiagHandler = diagnosticHandler; + c.PreCodeGenPassesHook = [](legacy::PassManager &pm) { +if (EnableGlobalMergeFunc) + pm.add(createGlobalMergeFuncPass()); + }; c.AlwaysEmitRegularLTOObj = !config->ltoObjPath.empty(); c.TimeTraceEnabled = config->timeTraceEnabled; diff --git a/lld/test/MachO/cgdata-generate-merge.s b/lld/test/MachO/cgdata-generate-merge.s new file mode 100644 index 00..3f7fb6777bc3cf --- /dev/null +++ b/lld/test/MachO/cgdata-generate-merge.s @@ -0,0 +1,85 @@ +# UNSUPPORTED: system-windows +# REQUIRES: aarch64 + +# RUN: rm -rf %t; split-file %s %t + +# Synthesize raw cgdata without the header (32 byte) from the indexed cgdata. +# RUN: llvm-cgdata --convert --format binary %t/raw-1.cgtext -o %t/raw-1.cgdata +# RUN: od -t x1 -j 32 -An %t/raw-1.cgdata | tr -d '\n\r\t' | sed 's/[ ][ ]*/ /g; s/^[ ]*//; s/[ ]*$//; s/[ ]/,0x/g; s/^/0x/' > %t/raw-1-bytes.txt +# RUN: sed "s//$(cat %t/raw-1-bytes.txt)/g" %t/merge-template.s > %t/merge-1.s +# RUN: llvm-cgdata --convert --format binary %t/raw-2.cgtext -o %t/raw-2.cgdata +# RUN: od -t x1 -j
[llvm-branch-commits] [llvm] [CGData] Global Merge Functions (PR #112671)
https://github.com/kyulee-com edited https://github.com/llvm/llvm-project/pull/112671 ___ 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/HIP: Remove requires system-linux from some driver tests (PR #112842)
llvmbot wrote: @llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-driver Author: Matt Arsenault (arsenm) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/112842.diff 2 Files Affected: - (modified) clang/test/Driver/hip-partial-link.hip (+1-1) - (modified) clang/test/Driver/linker-wrapper.c (+4-6) ``diff diff --git a/clang/test/Driver/hip-partial-link.hip b/clang/test/Driver/hip-partial-link.hip index 8b27f78f3bdd12..5580e569780194 100644 --- a/clang/test/Driver/hip-partial-link.hip +++ b/clang/test/Driver/hip-partial-link.hip @@ -1,4 +1,4 @@ -// REQUIRES: x86-registered-target, amdgpu-registered-target, lld, system-linux +// REQUIRES: x86-registered-target, amdgpu-registered-target, lld // RUN: %clang -x hip --target=x86_64-unknown-linux-gnu --no-offload-new-driver \ // RUN: --offload-arch=gfx906 -c -nostdinc -nogpuinc -nohipwrapperinc \ diff --git a/clang/test/Driver/linker-wrapper.c b/clang/test/Driver/linker-wrapper.c index 068ea2d7d3c663..89492ee9574cb8 100644 --- a/clang/test/Driver/linker-wrapper.c +++ b/clang/test/Driver/linker-wrapper.c @@ -2,8 +2,6 @@ // REQUIRES: nvptx-registered-target // REQUIRES: amdgpu-registered-target -// REQUIRES: system-linux - // An externally visible variable so static libraries extract. __attribute__((visibility("protected"), used)) int x; @@ -30,7 +28,7 @@ __attribute__((visibility("protected"), used)) int x; // RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run --device-debug -O0 \ // RUN: --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=NVPTX-LINK-DEBUG -// NVPTX-LINK-DEBUG: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_70 -O2 -flto {{.*}}.o {{.*}}.o -g +// NVPTX-LINK-DEBUG: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_70 -O2 -flto {{.*}}.o {{.*}}.o -g // RUN: clang-offload-packager -o %t.out \ // RUN: --image=file=%t.elf.o,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx908 \ @@ -93,7 +91,7 @@ __attribute__((visibility("protected"), used)) int x; // CUDA: clang{{.*}} -o [[IMG_SM70:.+]] --target=nvptx64-nvidia-cuda -march=sm_70 // CUDA: clang{{.*}} -o [[IMG_SM52:.+]] --target=nvptx64-nvidia-cuda -march=sm_52 -// CUDA: fatbinary{{.*}}-64 --create {{.*}}.fatbin --image=profile=sm_70,file=[[IMG_SM70]] --image=profile=sm_52,file=[[IMG_SM52]] +// CUDA: fatbinary{{.*}}-64 --create {{.*}}.fatbin --image=profile=sm_70,file=[[IMG_SM70]] --image=profile=sm_52,file=[[IMG_SM52]] // CUDA: usr/bin/ld{{.*}} {{.*}}.openmp.image.{{.*}}.o {{.*}}.cuda.image.{{.*}}.o // RUN: clang-offload-packager -o %t.out \ @@ -120,7 +118,7 @@ __attribute__((visibility("protected"), used)) int x; // HIP: clang{{.*}} -o [[IMG_GFX90A:.+]] --target=amdgcn-amd-amdhsa -mcpu=gfx90a // HIP: clang{{.*}} -o [[IMG_GFX908:.+]] --target=amdgcn-amd-amdhsa -mcpu=gfx908 -// HIP: clang-offload-bundler{{.*}}-type=o -bundle-align=4096 -compress -compression-level=6 -targets=host-x86_64-unknown-linux,hip-amdgcn-amd-amdhsa--gfx90a,hip-amdgcn-amd-amdhsa--gfx908 -input=/dev/null -input=[[IMG_GFX90A]] -input=[[IMG_GFX908]] -output={{.*}}.hipfb +// HIP: clang-offload-bundler{{.*}}-type=o -bundle-align=4096 -compress -compression-level=6 -targets=host-x86_64-unknown-linux,hip-amdgcn-amd-amdhsa--gfx90a,hip-amdgcn-amd-amdhsa--gfx908 -input={{/dev/null|NUL}} -input=[[IMG_GFX90A]] -input=[[IMG_GFX908]] -output={{.*}}.hipfb // RUN: clang-offload-packager -o %t.out \ // RUN: --image=file=%t.elf.o,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx908 \ @@ -211,7 +209,7 @@ __attribute__((visibility("protected"), used)) int x; // RUN: %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=RELOCATABLE-LINK-HIP // RELOCATABLE-LINK-HIP: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -// RELOCATABLE-LINK-HIP: clang-offload-bundler{{.*}} -type=o -bundle-align=4096 -targets=host-x86_64-unknown-linux,hip-amdgcn-amd-amdhsa--gfx90a -input=/dev/null -input={{.*}} -output={{.*}} +// RELOCATABLE-LINK-HIP: clang-offload-bundler{{.*}} -type=o -bundle-align=4096 -targets=host-x86_64-unknown-linux,hip-amdgcn-amd-amdhsa--gfx90a -input={{/dev/null|NUL}} -input={{.*}} -output={{.*}} // RELOCATABLE-LINK-HIP: /usr/bin/ld.lld{{.*}}-r // RELOCATABLE-LINK-HIP: llvm-objcopy{{.*}}a.out --remove-section .llvm.offloading `` https://github.com/llvm/llvm-project/pull/112842 ___ 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/HIP: Remove requires system-linux from some driver tests (PR #112842)
llvmbot wrote: @llvm/pr-subscribers-backend-amdgpu Author: Matt Arsenault (arsenm) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/112842.diff 2 Files Affected: - (modified) clang/test/Driver/hip-partial-link.hip (+1-1) - (modified) clang/test/Driver/linker-wrapper.c (+4-6) ``diff diff --git a/clang/test/Driver/hip-partial-link.hip b/clang/test/Driver/hip-partial-link.hip index 8b27f78f3bdd12..5580e569780194 100644 --- a/clang/test/Driver/hip-partial-link.hip +++ b/clang/test/Driver/hip-partial-link.hip @@ -1,4 +1,4 @@ -// REQUIRES: x86-registered-target, amdgpu-registered-target, lld, system-linux +// REQUIRES: x86-registered-target, amdgpu-registered-target, lld // RUN: %clang -x hip --target=x86_64-unknown-linux-gnu --no-offload-new-driver \ // RUN: --offload-arch=gfx906 -c -nostdinc -nogpuinc -nohipwrapperinc \ diff --git a/clang/test/Driver/linker-wrapper.c b/clang/test/Driver/linker-wrapper.c index 068ea2d7d3c663..89492ee9574cb8 100644 --- a/clang/test/Driver/linker-wrapper.c +++ b/clang/test/Driver/linker-wrapper.c @@ -2,8 +2,6 @@ // REQUIRES: nvptx-registered-target // REQUIRES: amdgpu-registered-target -// REQUIRES: system-linux - // An externally visible variable so static libraries extract. __attribute__((visibility("protected"), used)) int x; @@ -30,7 +28,7 @@ __attribute__((visibility("protected"), used)) int x; // RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run --device-debug -O0 \ // RUN: --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=NVPTX-LINK-DEBUG -// NVPTX-LINK-DEBUG: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_70 -O2 -flto {{.*}}.o {{.*}}.o -g +// NVPTX-LINK-DEBUG: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_70 -O2 -flto {{.*}}.o {{.*}}.o -g // RUN: clang-offload-packager -o %t.out \ // RUN: --image=file=%t.elf.o,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx908 \ @@ -93,7 +91,7 @@ __attribute__((visibility("protected"), used)) int x; // CUDA: clang{{.*}} -o [[IMG_SM70:.+]] --target=nvptx64-nvidia-cuda -march=sm_70 // CUDA: clang{{.*}} -o [[IMG_SM52:.+]] --target=nvptx64-nvidia-cuda -march=sm_52 -// CUDA: fatbinary{{.*}}-64 --create {{.*}}.fatbin --image=profile=sm_70,file=[[IMG_SM70]] --image=profile=sm_52,file=[[IMG_SM52]] +// CUDA: fatbinary{{.*}}-64 --create {{.*}}.fatbin --image=profile=sm_70,file=[[IMG_SM70]] --image=profile=sm_52,file=[[IMG_SM52]] // CUDA: usr/bin/ld{{.*}} {{.*}}.openmp.image.{{.*}}.o {{.*}}.cuda.image.{{.*}}.o // RUN: clang-offload-packager -o %t.out \ @@ -120,7 +118,7 @@ __attribute__((visibility("protected"), used)) int x; // HIP: clang{{.*}} -o [[IMG_GFX90A:.+]] --target=amdgcn-amd-amdhsa -mcpu=gfx90a // HIP: clang{{.*}} -o [[IMG_GFX908:.+]] --target=amdgcn-amd-amdhsa -mcpu=gfx908 -// HIP: clang-offload-bundler{{.*}}-type=o -bundle-align=4096 -compress -compression-level=6 -targets=host-x86_64-unknown-linux,hip-amdgcn-amd-amdhsa--gfx90a,hip-amdgcn-amd-amdhsa--gfx908 -input=/dev/null -input=[[IMG_GFX90A]] -input=[[IMG_GFX908]] -output={{.*}}.hipfb +// HIP: clang-offload-bundler{{.*}}-type=o -bundle-align=4096 -compress -compression-level=6 -targets=host-x86_64-unknown-linux,hip-amdgcn-amd-amdhsa--gfx90a,hip-amdgcn-amd-amdhsa--gfx908 -input={{/dev/null|NUL}} -input=[[IMG_GFX90A]] -input=[[IMG_GFX908]] -output={{.*}}.hipfb // RUN: clang-offload-packager -o %t.out \ // RUN: --image=file=%t.elf.o,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx908 \ @@ -211,7 +209,7 @@ __attribute__((visibility("protected"), used)) int x; // RUN: %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=RELOCATABLE-LINK-HIP // RELOCATABLE-LINK-HIP: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -// RELOCATABLE-LINK-HIP: clang-offload-bundler{{.*}} -type=o -bundle-align=4096 -targets=host-x86_64-unknown-linux,hip-amdgcn-amd-amdhsa--gfx90a -input=/dev/null -input={{.*}} -output={{.*}} +// RELOCATABLE-LINK-HIP: clang-offload-bundler{{.*}} -type=o -bundle-align=4096 -targets=host-x86_64-unknown-linux,hip-amdgcn-amd-amdhsa--gfx90a -input={{/dev/null|NUL}} -input={{.*}} -output={{.*}} // RELOCATABLE-LINK-HIP: /usr/bin/ld.lld{{.*}}-r // RELOCATABLE-LINK-HIP: llvm-objcopy{{.*}}a.out --remove-section .llvm.offloading `` https://github.com/llvm/llvm-project/pull/112842 ___ 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/HIP: Remove requires system-linux from some driver tests (PR #112842)
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/112842?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#112842** https://app.graphite.dev/github/pr/llvm/llvm-project/112842?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> 👈 * **#111976** https://app.graphite.dev/github/pr/llvm/llvm-project/111976?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#111975** https://app.graphite.dev/github/pr/llvm/llvm-project/111975?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * `main` This stack of pull requests is managed by Graphite. https://stacking.dev/?utm_source=stack-comment";>Learn more about stacking. Join @arsenm and the rest of your teammates on https://graphite.dev?utm-source=stack-comment";>https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="11px" height="11px"/> Graphite https://github.com/llvm/llvm-project/pull/112842 ___ 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/HIP: Remove requires system-linux from some driver tests (PR #112842)
https://github.com/arsenm ready_for_review https://github.com/llvm/llvm-project/pull/112842 ___ 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/HIP: Remove requires system-linux from some driver tests (PR #112842)
https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/112842 None >From 2951ca1579e7249fc513dd69e10c10cbd7441c1a Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Fri, 18 Oct 2024 09:40:34 +0400 Subject: [PATCH] clang/HIP: Remove requires system-linux from some driver tests --- clang/test/Driver/hip-partial-link.hip | 2 +- clang/test/Driver/linker-wrapper.c | 10 -- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/clang/test/Driver/hip-partial-link.hip b/clang/test/Driver/hip-partial-link.hip index 8b27f78f3bdd12..5580e569780194 100644 --- a/clang/test/Driver/hip-partial-link.hip +++ b/clang/test/Driver/hip-partial-link.hip @@ -1,4 +1,4 @@ -// REQUIRES: x86-registered-target, amdgpu-registered-target, lld, system-linux +// REQUIRES: x86-registered-target, amdgpu-registered-target, lld // RUN: %clang -x hip --target=x86_64-unknown-linux-gnu --no-offload-new-driver \ // RUN: --offload-arch=gfx906 -c -nostdinc -nogpuinc -nohipwrapperinc \ diff --git a/clang/test/Driver/linker-wrapper.c b/clang/test/Driver/linker-wrapper.c index 068ea2d7d3c663..89492ee9574cb8 100644 --- a/clang/test/Driver/linker-wrapper.c +++ b/clang/test/Driver/linker-wrapper.c @@ -2,8 +2,6 @@ // REQUIRES: nvptx-registered-target // REQUIRES: amdgpu-registered-target -// REQUIRES: system-linux - // An externally visible variable so static libraries extract. __attribute__((visibility("protected"), used)) int x; @@ -30,7 +28,7 @@ __attribute__((visibility("protected"), used)) int x; // RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run --device-debug -O0 \ // RUN: --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=NVPTX-LINK-DEBUG -// NVPTX-LINK-DEBUG: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_70 -O2 -flto {{.*}}.o {{.*}}.o -g +// NVPTX-LINK-DEBUG: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_70 -O2 -flto {{.*}}.o {{.*}}.o -g // RUN: clang-offload-packager -o %t.out \ // RUN: --image=file=%t.elf.o,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx908 \ @@ -93,7 +91,7 @@ __attribute__((visibility("protected"), used)) int x; // CUDA: clang{{.*}} -o [[IMG_SM70:.+]] --target=nvptx64-nvidia-cuda -march=sm_70 // CUDA: clang{{.*}} -o [[IMG_SM52:.+]] --target=nvptx64-nvidia-cuda -march=sm_52 -// CUDA: fatbinary{{.*}}-64 --create {{.*}}.fatbin --image=profile=sm_70,file=[[IMG_SM70]] --image=profile=sm_52,file=[[IMG_SM52]] +// CUDA: fatbinary{{.*}}-64 --create {{.*}}.fatbin --image=profile=sm_70,file=[[IMG_SM70]] --image=profile=sm_52,file=[[IMG_SM52]] // CUDA: usr/bin/ld{{.*}} {{.*}}.openmp.image.{{.*}}.o {{.*}}.cuda.image.{{.*}}.o // RUN: clang-offload-packager -o %t.out \ @@ -120,7 +118,7 @@ __attribute__((visibility("protected"), used)) int x; // HIP: clang{{.*}} -o [[IMG_GFX90A:.+]] --target=amdgcn-amd-amdhsa -mcpu=gfx90a // HIP: clang{{.*}} -o [[IMG_GFX908:.+]] --target=amdgcn-amd-amdhsa -mcpu=gfx908 -// HIP: clang-offload-bundler{{.*}}-type=o -bundle-align=4096 -compress -compression-level=6 -targets=host-x86_64-unknown-linux,hip-amdgcn-amd-amdhsa--gfx90a,hip-amdgcn-amd-amdhsa--gfx908 -input=/dev/null -input=[[IMG_GFX90A]] -input=[[IMG_GFX908]] -output={{.*}}.hipfb +// HIP: clang-offload-bundler{{.*}}-type=o -bundle-align=4096 -compress -compression-level=6 -targets=host-x86_64-unknown-linux,hip-amdgcn-amd-amdhsa--gfx90a,hip-amdgcn-amd-amdhsa--gfx908 -input={{/dev/null|NUL}} -input=[[IMG_GFX90A]] -input=[[IMG_GFX908]] -output={{.*}}.hipfb // RUN: clang-offload-packager -o %t.out \ // RUN: --image=file=%t.elf.o,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx908 \ @@ -211,7 +209,7 @@ __attribute__((visibility("protected"), used)) int x; // RUN: %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=RELOCATABLE-LINK-HIP // RELOCATABLE-LINK-HIP: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -// RELOCATABLE-LINK-HIP: clang-offload-bundler{{.*}} -type=o -bundle-align=4096 -targets=host-x86_64-unknown-linux,hip-amdgcn-amd-amdhsa--gfx90a -input=/dev/null -input={{.*}} -output={{.*}} +// RELOCATABLE-LINK-HIP: clang-offload-bundler{{.*}} -type=o -bundle-align=4096 -targets=host-x86_64-unknown-linux,hip-amdgcn-amd-amdhsa--gfx90a -input={{/dev/null|NUL}} -input={{.*}} -output={{.*}} // RELOCATABLE-LINK-HIP: /usr/bin/ld.lld{{.*}}-r // RELOCATABLE-LINK-HIP: llvm-objcopy{{.*}}a.out --remove-section .llvm.offloading ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] AMDGPU: Add baseline tests for cmpxchg custom expansion (PR #109408)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/109408 >From 3cf356ca6ad7dd2a4c7d07635e69dbde1694afb8 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Thu, 12 Sep 2024 12:44:04 +0400 Subject: [PATCH] AMDGPU: Add baseline tests for cmpxchg custom expansion We need a non-atomic path if flat may access private. --- .../AMDGPU/flat_atomics_i64_noprivate.ll | 34 +-- .../AtomicExpand/AMDGPU/expand-atomic-mmra.ll | 12 +- ...and-atomic-rmw-fadd-flat-specialization.ll | 4 +- ...expand-atomicrmw-flat-noalias-addrspace.ll | 149 - .../expand-cmpxchg-flat-maybe-private.ll | 208 ++ 5 files changed, 382 insertions(+), 25 deletions(-) create mode 100644 llvm/test/Transforms/AtomicExpand/AMDGPU/expand-cmpxchg-flat-maybe-private.ll diff --git a/llvm/test/CodeGen/AMDGPU/flat_atomics_i64_noprivate.ll b/llvm/test/CodeGen/AMDGPU/flat_atomics_i64_noprivate.ll index 64bd4804ccd519..d9c6e4ad5006ac 100644 --- a/llvm/test/CodeGen/AMDGPU/flat_atomics_i64_noprivate.ll +++ b/llvm/test/CodeGen/AMDGPU/flat_atomics_i64_noprivate.ll @@ -5005,7 +5005,7 @@ define amdgpu_kernel void @atomic_cmpxchg_i64_offset(ptr %out, i64 %in, i64 %old ; GFX12-NEXT:s_endpgm entry: %gep = getelementptr i64, ptr %out, i64 4 - %val = cmpxchg volatile ptr %gep, i64 %old, i64 %in syncscope("agent") seq_cst seq_cst + %val = cmpxchg volatile ptr %gep, i64 %old, i64 %in syncscope("agent") seq_cst seq_cst, !noalias.addrspace !0 ret void } @@ -5061,7 +5061,7 @@ define amdgpu_kernel void @atomic_cmpxchg_i64_soffset(ptr %out, i64 %in, i64 %ol ; GFX12-NEXT:s_endpgm entry: %gep = getelementptr i64, ptr %out, i64 9000 - %val = cmpxchg volatile ptr %gep, i64 %old, i64 %in syncscope("agent") seq_cst seq_cst + %val = cmpxchg volatile ptr %gep, i64 %old, i64 %in syncscope("agent") seq_cst seq_cst, !noalias.addrspace !0 ret void } @@ -5121,7 +5121,7 @@ define amdgpu_kernel void @atomic_cmpxchg_i64_ret_offset(ptr %out, ptr %out2, i6 ; GFX12-NEXT:s_endpgm entry: %gep = getelementptr i64, ptr %out, i64 4 - %val = cmpxchg volatile ptr %gep, i64 %old, i64 %in syncscope("agent") seq_cst seq_cst + %val = cmpxchg volatile ptr %gep, i64 %old, i64 %in syncscope("agent") seq_cst seq_cst, !noalias.addrspace !0 %extract0 = extractvalue { i64, i1 } %val, 0 store i64 %extract0, ptr %out2 ret void @@ -5184,7 +5184,7 @@ define amdgpu_kernel void @atomic_cmpxchg_i64_addr64_offset(ptr %out, i64 %in, i entry: %ptr = getelementptr i64, ptr %out, i64 %index %gep = getelementptr i64, ptr %ptr, i64 4 - %val = cmpxchg volatile ptr %gep, i64 %old, i64 %in syncscope("agent") seq_cst seq_cst + %val = cmpxchg volatile ptr %gep, i64 %old, i64 %in syncscope("agent") seq_cst seq_cst, !noalias.addrspace !0 ret void } @@ -5257,7 +5257,7 @@ define amdgpu_kernel void @atomic_cmpxchg_i64_ret_addr64_offset(ptr %out, ptr %o entry: %ptr = getelementptr i64, ptr %out, i64 %index %gep = getelementptr i64, ptr %ptr, i64 4 - %val = cmpxchg volatile ptr %gep, i64 %old, i64 %in syncscope("agent") seq_cst seq_cst + %val = cmpxchg volatile ptr %gep, i64 %old, i64 %in syncscope("agent") seq_cst seq_cst, !noalias.addrspace !0 %extract0 = extractvalue { i64, i1 } %val, 0 store i64 %extract0, ptr %out2 ret void @@ -5310,7 +5310,7 @@ define amdgpu_kernel void @atomic_cmpxchg_i64(ptr %out, i64 %in, i64 %old) { ; GFX12-NEXT:global_inv scope:SCOPE_DEV ; GFX12-NEXT:s_endpgm entry: - %val = cmpxchg volatile ptr %out, i64 %old, i64 %in syncscope("agent") seq_cst seq_cst + %val = cmpxchg volatile ptr %out, i64 %old, i64 %in syncscope("agent") seq_cst seq_cst, !noalias.addrspace !0 ret void } @@ -5365,7 +5365,7 @@ define amdgpu_kernel void @atomic_cmpxchg_i64_ret(ptr %out, ptr %out2, i64 %in, ; GFX12-NEXT:flat_store_b64 v[2:3], v[0:1] ; GFX12-NEXT:s_endpgm entry: - %val = cmpxchg volatile ptr %out, i64 %old, i64 %in syncscope("agent") seq_cst seq_cst + %val = cmpxchg volatile ptr %out, i64 %old, i64 %in syncscope("agent") seq_cst seq_cst, !noalias.addrspace !0 %extract0 = extractvalue { i64, i1 } %val, 0 store i64 %extract0, ptr %out2 ret void @@ -5423,7 +5423,7 @@ define amdgpu_kernel void @atomic_cmpxchg_i64_addr64(ptr %out, i64 %in, i64 %ind ; GFX12-NEXT:s_endpgm entry: %ptr = getelementptr i64, ptr %out, i64 %index - %val = cmpxchg volatile ptr %ptr, i64 %old, i64 %in syncscope("agent") seq_cst seq_cst + %val = cmpxchg volatile ptr %ptr, i64 %old, i64 %in syncscope("agent") seq_cst seq_cst, !noalias.addrspace !0 ret void } @@ -5491,7 +5491,7 @@ define amdgpu_kernel void @atomic_cmpxchg_i64_ret_addr64(ptr %out, ptr %out2, i6 ; GFX12-NEXT:s_endpgm entry: %ptr = getelementptr i64, ptr %out, i64 %index - %val = cmpxchg volatile ptr %ptr, i64 %old, i64 %in syncscope("agent") seq_cst seq_cst + %val = cmpxchg volatile ptr %ptr, i64 %old, i64 %in syncscope("agent") seq_cst se
[llvm-branch-commits] [libc] [libc][math][c23] Add logf16 C23 math function (PR #106072)
https://github.com/lntue edited https://github.com/llvm/llvm-project/pull/106072 ___ 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/19.x: [clang-format] Handle template opener/closer in braced list (#112494) (PR #112815)
https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/112815 Backport 67f576f31d661897c5da302b8611decb7e0f9237 Requested by: @owenca >From d2c97f90d9b1fe0d6f239c6bf6483632be05483e Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Thu, 17 Oct 2024 19:56:09 -0700 Subject: [PATCH] [clang-format] Handle template opener/closer in braced list (#112494) Fixes #112487. (cherry picked from commit 67f576f31d661897c5da302b8611decb7e0f9237) --- clang/lib/Format/UnwrappedLineParser.cpp | 5 + clang/unittests/Format/TokenAnnotatorTest.cpp | 6 ++ 2 files changed, 11 insertions(+) diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 631c7c62baac18..a5268e153bcc5b 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -2500,6 +2500,11 @@ bool UnwrappedLineParser::parseBracedList(bool IsAngleBracket, bool IsEnum) { // Assume there are no blocks inside a braced init list apart // from the ones we explicitly parse out (like lambdas). FormatTok->setBlockKind(BK_BracedInit); + if (!IsAngleBracket) { +auto *Prev = FormatTok->Previous; +if (Prev && Prev->is(tok::greater)) + Prev->setFinalizedType(TT_TemplateCloser); + } nextToken(); parseBracedList(); break; diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 6f3ef3b646c619..4acd900ff061f8 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -3404,6 +3404,12 @@ TEST_F(TokenAnnotatorTest, TemplateInstantiation) { ASSERT_EQ(Tokens.size(), 21u) << Tokens; EXPECT_TOKEN(Tokens[4], tok::less, TT_TemplateOpener); EXPECT_TOKEN(Tokens[16], tok::greater, TT_TemplateCloser); + + Tokens = + annotate("auto x{std::conditional_t{}};"); + ASSERT_EQ(Tokens.size(), 24u) << Tokens; + EXPECT_TOKEN(Tokens[6], tok::less, TT_TemplateOpener); + EXPECT_TOKEN(Tokens[18], tok::greater, TT_TemplateCloser); } } // namespace ___ 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/19.x: [clang-format] Handle template opener/closer in braced list (#112494) (PR #112815)
https://github.com/llvmbot milestoned https://github.com/llvm/llvm-project/pull/112815 ___ 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/19.x: [clang-format] Handle template opener/closer in braced list (#112494) (PR #112815)
llvmbot wrote: @llvm/pr-subscribers-clang-format Author: None (llvmbot) Changes Backport 67f576f31d661897c5da302b8611decb7e0f9237 Requested by: @owenca --- Full diff: https://github.com/llvm/llvm-project/pull/112815.diff 2 Files Affected: - (modified) clang/lib/Format/UnwrappedLineParser.cpp (+5) - (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+6) ``diff diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 631c7c62baac18..a5268e153bcc5b 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -2500,6 +2500,11 @@ bool UnwrappedLineParser::parseBracedList(bool IsAngleBracket, bool IsEnum) { // Assume there are no blocks inside a braced init list apart // from the ones we explicitly parse out (like lambdas). FormatTok->setBlockKind(BK_BracedInit); + if (!IsAngleBracket) { +auto *Prev = FormatTok->Previous; +if (Prev && Prev->is(tok::greater)) + Prev->setFinalizedType(TT_TemplateCloser); + } nextToken(); parseBracedList(); break; diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 6f3ef3b646c619..4acd900ff061f8 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -3404,6 +3404,12 @@ TEST_F(TokenAnnotatorTest, TemplateInstantiation) { ASSERT_EQ(Tokens.size(), 21u) << Tokens; EXPECT_TOKEN(Tokens[4], tok::less, TT_TemplateOpener); EXPECT_TOKEN(Tokens[16], tok::greater, TT_TemplateCloser); + + Tokens = + annotate("auto x{std::conditional_t{}};"); + ASSERT_EQ(Tokens.size(), 24u) << Tokens; + EXPECT_TOKEN(Tokens[6], tok::less, TT_TemplateOpener); + EXPECT_TOKEN(Tokens[18], tok::greater, TT_TemplateCloser); } } // namespace `` https://github.com/llvm/llvm-project/pull/112815 ___ 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/19.x: [clang-format] Handle template opener/closer in braced list (#112494) (PR #112815)
llvmbot wrote: @mydeveloperday What do you think about merging this PR to the release branch? https://github.com/llvm/llvm-project/pull/112815 ___ 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] [StructuralHash] Support Differences (PR #112638)
https://github.com/kyulee-com edited https://github.com/llvm/llvm-project/pull/112638 ___ 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] [lld] [CGData][lld-macho] Add Global Merge Func Pass (PR #112674)
https://github.com/kyulee-com edited https://github.com/llvm/llvm-project/pull/112674 ___ 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] [lld] [llvm] [CGData][llvm-cgdata] Support for stable function map (PR #112664)
https://github.com/kyulee-com edited https://github.com/llvm/llvm-project/pull/112664 ___ 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] [StructuralHash] Support Differences (PR #112638)
https://github.com/kyulee-com edited https://github.com/llvm/llvm-project/pull/112638 ___ 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] [CGData] Stable Function Map (PR #112662)
https://github.com/kyulee-com edited https://github.com/llvm/llvm-project/pull/112662 ___ 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] [libc] [libc][math][c23] Add logf16 C23 math function (PR #106072)
@@ -287,6 +287,34 @@ template LIBC_INLINE float16 eval_sinh_or_cosh(float16 x) { lo, half_p_odd * exp2_hi_mid_diff, half_p_even * exp2_hi_mid_sum)); } +// Generated by Sollya with the following commands: +// > display = hexadecimal; +// > for i from 0 to 31 do print(round(log(1 + i * 2^-5), SG, RN)); +constexpr cpp::array LOGF_F = { +0x0p+0f,0x1.f829bp-6f, 0x1.f0a30cp-5f, 0x1.6f0d28p-4f, +0x1.e27076p-4f, 0x1.29553p-3f, 0x1.5ff308p-3f, 0x1.9525aap-3f, +0x1.c8ff7cp-3f, 0x1.fb9186p-3f, 0x1.1675cap-2f, 0x1.2e8e2cp-2f, +0x1.4618bcp-2f, 0x1.5d1bdcp-2f, 0x1.739d8p-2f, 0x1.89a338p-2f, +0x1.9f323ep-2f, 0x1.b44f78p-2f, 0x1.c8ff7cp-2f, 0x1.dd46ap-2f, +0x1.f128f6p-2f, 0x1.02552ap-1f, 0x1.0be72ep-1f, 0x1.154c3ep-1f, +0x1.1e85f6p-1f, 0x1.2795e2p-1f, 0x1.307d74p-1f, 0x1.393e0ep-1f, +0x1.41d8fep-1f, 0x1.4a4f86p-1f, 0x1.52a2d2p-1f, 0x1.5ad404p-1f, +}; + +// Generated by Sollya with the following commands: +// > display = hexadecimal; +// > for i from 0 to 31 do print(round(1 / (1 + i * 2^-5), SG, RN)); +constexpr cpp::array ONE_OVER_F = { lntue wrote: yes,Ithinkwe should at least add type suffix to these tables. https://github.com/llvm/llvm-project/pull/106072 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] AMDGPU: Custom expand flat cmpxchg which may access private (PR #109410)
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/109410 >From 671718564c70f4e7dc06bfb86a4cd07bf24315ed Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Wed, 14 Aug 2024 13:57:14 +0400 Subject: [PATCH 1/2] AMDGPU: Custom expand flat cmpxchg which may access private 64-bit flat cmpxchg instructions do not work correctly for scratch addresses, and need to be expanded as non-atomic. Allow custom expansion of cmpxchg in AtomicExpand, as is already the case for atomicrmw. --- llvm/include/llvm/CodeGen/TargetLowering.h|5 + .../llvm/Transforms/Utils/LowerAtomic.h |7 + llvm/lib/CodeGen/AtomicExpandPass.cpp |4 + llvm/lib/Target/AMDGPU/SIISelLowering.cpp | 146 ++- llvm/lib/Target/AMDGPU/SIISelLowering.h |3 + llvm/lib/Transforms/Utils/LowerAtomic.cpp | 21 +- llvm/test/CodeGen/AMDGPU/flat_atomics_i64.ll | 1019 +++-- ...expand-atomicrmw-flat-noalias-addrspace.ll |6 +- ...expand-atomicrmw-integer-ops-0-to-add-0.ll |6 +- .../expand-cmpxchg-flat-maybe-private.ll | 104 +- 10 files changed, 1157 insertions(+), 164 deletions(-) diff --git a/llvm/include/llvm/CodeGen/TargetLowering.h b/llvm/include/llvm/CodeGen/TargetLowering.h index 61615cb0f7b301..14f14513ae56a4 100644 --- a/llvm/include/llvm/CodeGen/TargetLowering.h +++ b/llvm/include/llvm/CodeGen/TargetLowering.h @@ -2204,6 +2204,11 @@ class TargetLoweringBase { "Generic atomicrmw expansion unimplemented on this target"); } + /// Perform a cmpxchg expansion using a target-specific method. + virtual void emitExpandAtomicCmpXchg(AtomicCmpXchgInst *CI) const { +llvm_unreachable("Generic cmpxchg expansion unimplemented on this target"); + } + /// Perform a bit test atomicrmw using a target-specific intrinsic. This /// represents the combined bit test intrinsic which will be lowered at a late /// stage by the backend. diff --git a/llvm/include/llvm/Transforms/Utils/LowerAtomic.h b/llvm/include/llvm/Transforms/Utils/LowerAtomic.h index b25b281667f9cb..295c2bd2b4b47e 100644 --- a/llvm/include/llvm/Transforms/Utils/LowerAtomic.h +++ b/llvm/include/llvm/Transforms/Utils/LowerAtomic.h @@ -23,6 +23,13 @@ class IRBuilderBase; /// Convert the given Cmpxchg into primitive load and compare. bool lowerAtomicCmpXchgInst(AtomicCmpXchgInst *CXI); +/// Emit IR to implement the given cmpxchg operation on values in registers, +/// returning the new value. +std::pair buildAtomicCmpXchgValue(IRBuilderBase &Builder, +Value *Ptr, Value *Cmp, +Value *Val, +Align Alignment); + /// Convert the given RMWI into primitive load and stores, /// assuming that doing so is legal. Return true if the lowering /// succeeds. diff --git a/llvm/lib/CodeGen/AtomicExpandPass.cpp b/llvm/lib/CodeGen/AtomicExpandPass.cpp index 0aff4f1f5cf1cb..1471e3d7cbc29d 100644 --- a/llvm/lib/CodeGen/AtomicExpandPass.cpp +++ b/llvm/lib/CodeGen/AtomicExpandPass.cpp @@ -1674,6 +1674,10 @@ bool AtomicExpandImpl::tryExpandAtomicCmpXchg(AtomicCmpXchgInst *CI) { return true; case TargetLoweringBase::AtomicExpansionKind::NotAtomic: return lowerAtomicCmpXchgInst(CI); + case TargetLoweringBase::AtomicExpansionKind::Expand: { +TLI->emitExpandAtomicCmpXchg(CI); +return true; + } } } diff --git a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp index 993ce8d6d04b52..2d3eb17b38dcc3 100644 --- a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp +++ b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp @@ -16595,9 +16595,21 @@ SITargetLowering::shouldExpandAtomicStoreInIR(StoreInst *SI) const { TargetLowering::AtomicExpansionKind SITargetLowering::shouldExpandAtomicCmpXchgInIR(AtomicCmpXchgInst *CmpX) const { - return CmpX->getPointerAddressSpace() == AMDGPUAS::PRIVATE_ADDRESS - ? AtomicExpansionKind::NotAtomic - : AtomicExpansionKind::None; + unsigned AddrSpace = CmpX->getPointerAddressSpace(); + if (AddrSpace == AMDGPUAS::PRIVATE_ADDRESS) +return AtomicExpansionKind::NotAtomic; + + if (AddrSpace != AMDGPUAS::FLAT_ADDRESS || !flatInstrMayAccessPrivate(CmpX)) +return AtomicExpansionKind::None; + + const DataLayout &DL = CmpX->getDataLayout(); + + Type *ValTy = CmpX->getNewValOperand()->getType(); + + // If a 64-bit flat atomic may alias private, we need to avoid using the + // atomic in the private case. + return DL.getTypeSizeInBits(ValTy) == 64 ? AtomicExpansionKind::Expand + : AtomicExpansionKind::None; } const TargetRegisterClass * @@ -16761,40 +16773,8 @@ bool SITargetLowering::checkForPhysRegDependency( return false; } -void SITargetLowering::emitExpandAtomicRMW(AtomicRMWInst *AI) const { - AtomicRMWInst::BinOp Op = AI->getOperation(); - - if (Op == AtomicRMWInst::Sub || Op ==
[llvm-branch-commits] [libc] [libc][math][c23] Add sqrtf16 C23 math function (PR #112406)
https://github.com/lntue approved this pull request. https://github.com/llvm/llvm-project/pull/112406 ___ 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] [Coverage] Make additional counters available for BranchRegion. NFC. (PR #112730)
llvmbot wrote: @llvm/pr-subscribers-clang-codegen Author: NAKAMURA Takumi (chapuni) Changes `getBranchCounterPair()` allocates an additional Counter to SkipPath in `SingleByteCoverage`. `IsCounterEqual()` calculates the comparison with rewinding counter replacements. `NumRegionCounters` is updated to take additional counters in account. `incrementProfileCounter()` has a few additiona arguments. - `UseSkipPath=true`, to specify setting counters for SkipPath. It assumes `UseSkipPath=false` is used together. - `UseBoth` may be specified for marking another path. It introduces the same effect as issueing `markStmtAsUsed(!SkipPath, S)`. `llvm-cov` discovers counters in `FalseCount` to allocate `MaxCounterID` for empty profile data. --- Full diff: https://github.com/llvm/llvm-project/pull/112730.diff 5 Files Affected: - (modified) clang/lib/CodeGen/CodeGenFunction.h (+7-1) - (modified) clang/lib/CodeGen/CodeGenPGO.cpp (+29-2) - (modified) clang/lib/CodeGen/CodeGenPGO.h (+1) - (modified) clang/lib/CodeGen/CoverageMappingGen.cpp (+24-7) - (modified) llvm/lib/ProfileData/Coverage/CoverageMapping.cpp (+4) ``diff diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index 89ac3b342d0a7c..cb1192bf6e11fe 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -1629,11 +1629,17 @@ class CodeGenFunction : public CodeGenTypeCache { /// Increment the profiler's counter for the given statement by \p StepV. /// If \p StepV is null, the default increment is 1. void incrementProfileCounter(const Stmt *S, llvm::Value *StepV = nullptr) { +incrementProfileCounter(false, S, false, StepV); + } + + void incrementProfileCounter(bool UseSkipPath, const Stmt *S, + bool UseBoth = false, + llvm::Value *StepV = nullptr) { if (CGM.getCodeGenOpts().hasProfileClangInstr() && !CurFn->hasFnAttribute(llvm::Attribute::NoProfile) && !CurFn->hasFnAttribute(llvm::Attribute::SkipProfile)) { auto AL = ApplyDebugLocation::CreateArtificial(*this); - PGO.emitCounterSetOrIncrement(Builder, S, StepV); + PGO.emitCounterSetOrIncrement(Builder, S, UseSkipPath, UseBoth, StepV); } PGO.setCurrentStmt(S); } diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp index 069469e3de856b..aefd53e12088b4 100644 --- a/clang/lib/CodeGen/CodeGenPGO.cpp +++ b/clang/lib/CodeGen/CodeGenPGO.cpp @@ -1138,6 +1138,19 @@ void CodeGenPGO::emitCounterRegionMapping(const Decl *D) { if (CoverageMapping.empty()) return; + // Scan max(FalseCnt) and update NumRegionCounters. + unsigned MaxNumCounters = NumRegionCounters; + for (const auto [_, V] : *RegionCounterMap) { +auto HasCounters = V.getIsCounterPair(); +assert((!HasCounters.first || +MaxNumCounters > (V.first & CounterPair::Mask)) && + "TrueCnt should not be reassigned"); +if (HasCounters.second) + MaxNumCounters = + std::max(MaxNumCounters, (V.second & CounterPair::Mask) + 1); + } + NumRegionCounters = MaxNumCounters; + CGM.getCoverageMapping()->addFunctionMappingRecord( FuncNameVar, FuncName, FunctionHash, CoverageMapping); } @@ -1193,11 +1206,25 @@ std::pair CodeGenPGO::getIsCounterPair(const Stmt *S) const { } void CodeGenPGO::emitCounterSetOrIncrement(CGBuilderTy &Builder, const Stmt *S, + bool UseSkipPath, bool UseBoth, llvm::Value *StepV) { - if (!RegionCounterMap || !Builder.GetInsertBlock()) + if (!RegionCounterMap) return; - unsigned Counter = (*RegionCounterMap)[S].first; + unsigned Counter; + auto &TheMap = (*RegionCounterMap)[S]; + auto IsCounter = TheMap.getIsCounterPair(); + if (!UseSkipPath) { +assert(IsCounter.first); +Counter = (TheMap.first & CounterPair::Mask); + } else { +if (!IsCounter.second) + return; +Counter = (TheMap.second & CounterPair::Mask); + } + + if (!Builder.GetInsertBlock()) +return; // Make sure that pointer to global is passed in with zero addrspace // This is relevant during GPU profiling diff --git a/clang/lib/CodeGen/CodeGenPGO.h b/clang/lib/CodeGen/CodeGenPGO.h index 83f35785e5327d..8b769dd88d7f1e 100644 --- a/clang/lib/CodeGen/CodeGenPGO.h +++ b/clang/lib/CodeGen/CodeGenPGO.h @@ -112,6 +112,7 @@ class CodeGenPGO { public: std::pair getIsCounterPair(const Stmt *S) const; void emitCounterSetOrIncrement(CGBuilderTy &Builder, const Stmt *S, + bool UseFalsePath, bool UseBoth, llvm::Value *StepV); void emitMCDCTestVectorBitmapUpdate(CGBuilderTy &Builder, const Expr *S, Address MCDCCondBitmapAddr, diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp index a5d83e7a74
[llvm-branch-commits] [clang] [llvm] [Coverage] Make additional counters available for BranchRegion. NFC. (PR #112730)
llvmbot wrote: @llvm/pr-subscribers-clang Author: NAKAMURA Takumi (chapuni) Changes `getBranchCounterPair()` allocates an additional Counter to SkipPath in `SingleByteCoverage`. `IsCounterEqual()` calculates the comparison with rewinding counter replacements. `NumRegionCounters` is updated to take additional counters in account. `incrementProfileCounter()` has a few additiona arguments. - `UseSkipPath=true`, to specify setting counters for SkipPath. It assumes `UseSkipPath=false` is used together. - `UseBoth` may be specified for marking another path. It introduces the same effect as issueing `markStmtAsUsed(!SkipPath, S)`. `llvm-cov` discovers counters in `FalseCount` to allocate `MaxCounterID` for empty profile data. --- Full diff: https://github.com/llvm/llvm-project/pull/112730.diff 5 Files Affected: - (modified) clang/lib/CodeGen/CodeGenFunction.h (+7-1) - (modified) clang/lib/CodeGen/CodeGenPGO.cpp (+29-2) - (modified) clang/lib/CodeGen/CodeGenPGO.h (+1) - (modified) clang/lib/CodeGen/CoverageMappingGen.cpp (+24-7) - (modified) llvm/lib/ProfileData/Coverage/CoverageMapping.cpp (+4) ``diff diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index 89ac3b342d0a7c..cb1192bf6e11fe 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -1629,11 +1629,17 @@ class CodeGenFunction : public CodeGenTypeCache { /// Increment the profiler's counter for the given statement by \p StepV. /// If \p StepV is null, the default increment is 1. void incrementProfileCounter(const Stmt *S, llvm::Value *StepV = nullptr) { +incrementProfileCounter(false, S, false, StepV); + } + + void incrementProfileCounter(bool UseSkipPath, const Stmt *S, + bool UseBoth = false, + llvm::Value *StepV = nullptr) { if (CGM.getCodeGenOpts().hasProfileClangInstr() && !CurFn->hasFnAttribute(llvm::Attribute::NoProfile) && !CurFn->hasFnAttribute(llvm::Attribute::SkipProfile)) { auto AL = ApplyDebugLocation::CreateArtificial(*this); - PGO.emitCounterSetOrIncrement(Builder, S, StepV); + PGO.emitCounterSetOrIncrement(Builder, S, UseSkipPath, UseBoth, StepV); } PGO.setCurrentStmt(S); } diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp index 069469e3de856b..aefd53e12088b4 100644 --- a/clang/lib/CodeGen/CodeGenPGO.cpp +++ b/clang/lib/CodeGen/CodeGenPGO.cpp @@ -1138,6 +1138,19 @@ void CodeGenPGO::emitCounterRegionMapping(const Decl *D) { if (CoverageMapping.empty()) return; + // Scan max(FalseCnt) and update NumRegionCounters. + unsigned MaxNumCounters = NumRegionCounters; + for (const auto [_, V] : *RegionCounterMap) { +auto HasCounters = V.getIsCounterPair(); +assert((!HasCounters.first || +MaxNumCounters > (V.first & CounterPair::Mask)) && + "TrueCnt should not be reassigned"); +if (HasCounters.second) + MaxNumCounters = + std::max(MaxNumCounters, (V.second & CounterPair::Mask) + 1); + } + NumRegionCounters = MaxNumCounters; + CGM.getCoverageMapping()->addFunctionMappingRecord( FuncNameVar, FuncName, FunctionHash, CoverageMapping); } @@ -1193,11 +1206,25 @@ std::pair CodeGenPGO::getIsCounterPair(const Stmt *S) const { } void CodeGenPGO::emitCounterSetOrIncrement(CGBuilderTy &Builder, const Stmt *S, + bool UseSkipPath, bool UseBoth, llvm::Value *StepV) { - if (!RegionCounterMap || !Builder.GetInsertBlock()) + if (!RegionCounterMap) return; - unsigned Counter = (*RegionCounterMap)[S].first; + unsigned Counter; + auto &TheMap = (*RegionCounterMap)[S]; + auto IsCounter = TheMap.getIsCounterPair(); + if (!UseSkipPath) { +assert(IsCounter.first); +Counter = (TheMap.first & CounterPair::Mask); + } else { +if (!IsCounter.second) + return; +Counter = (TheMap.second & CounterPair::Mask); + } + + if (!Builder.GetInsertBlock()) +return; // Make sure that pointer to global is passed in with zero addrspace // This is relevant during GPU profiling diff --git a/clang/lib/CodeGen/CodeGenPGO.h b/clang/lib/CodeGen/CodeGenPGO.h index 83f35785e5327d..8b769dd88d7f1e 100644 --- a/clang/lib/CodeGen/CodeGenPGO.h +++ b/clang/lib/CodeGen/CodeGenPGO.h @@ -112,6 +112,7 @@ class CodeGenPGO { public: std::pair getIsCounterPair(const Stmt *S) const; void emitCounterSetOrIncrement(CGBuilderTy &Builder, const Stmt *S, + bool UseFalsePath, bool UseBoth, llvm::Value *StepV); void emitMCDCTestVectorBitmapUpdate(CGBuilderTy &Builder, const Expr *S, Address MCDCCondBitmapAddr, diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp index a5d83e7a743bbd..0b
[llvm-branch-commits] [clang] [llvm] [Coverage] Make additional counters available for BranchRegion. NFC. (PR #112730)
https://github.com/chapuni created https://github.com/llvm/llvm-project/pull/112730 `getBranchCounterPair()` allocates an additional Counter to SkipPath in `SingleByteCoverage`. `IsCounterEqual()` calculates the comparison with rewinding counter replacements. `NumRegionCounters` is updated to take additional counters in account. `incrementProfileCounter()` has a few additiona arguments. - `UseSkipPath=true`, to specify setting counters for SkipPath. It assumes `UseSkipPath=false` is used together. - `UseBoth` may be specified for marking another path. It introduces the same effect as issueing `markStmtAsUsed(!SkipPath, S)`. `llvm-cov` discovers counters in `FalseCount` to allocate `MaxCounterID` for empty profile data. >From 5e460594c8a2550c38c759b2e6f1c5dc4152f820 Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Thu, 17 Oct 2024 22:15:12 +0900 Subject: [PATCH] [Coverage] Make additional counters available for BranchRegion. NFC. `getBranchCounterPair()` allocates an additional Counter to SkipPath in `SingleByteCoverage`. `IsCounterEqual()` calculates the comparison with rewinding counter replacements. `NumRegionCounters` is updated to take additional counters in account. `incrementProfileCounter()` has a few additiona arguments. - `UseSkipPath=true`, to specify setting counters for SkipPath. It assumes `UseSkipPath=false` is used together. - `UseBoth` may be specified for marking another path. It introduces the same effect as issueing `markStmtAsUsed(!SkipPath, S)`. `llvm-cov` discovers counters in `FalseCount` to allocate `MaxCounterID` for empty profile data. --- clang/lib/CodeGen/CodeGenFunction.h | 8 - clang/lib/CodeGen/CodeGenPGO.cpp | 31 +-- clang/lib/CodeGen/CodeGenPGO.h| 1 + clang/lib/CodeGen/CoverageMappingGen.cpp | 31 ++- .../ProfileData/Coverage/CoverageMapping.cpp | 4 +++ 5 files changed, 65 insertions(+), 10 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index 89ac3b342d0a7c..cb1192bf6e11fe 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -1629,11 +1629,17 @@ class CodeGenFunction : public CodeGenTypeCache { /// Increment the profiler's counter for the given statement by \p StepV. /// If \p StepV is null, the default increment is 1. void incrementProfileCounter(const Stmt *S, llvm::Value *StepV = nullptr) { +incrementProfileCounter(false, S, false, StepV); + } + + void incrementProfileCounter(bool UseSkipPath, const Stmt *S, + bool UseBoth = false, + llvm::Value *StepV = nullptr) { if (CGM.getCodeGenOpts().hasProfileClangInstr() && !CurFn->hasFnAttribute(llvm::Attribute::NoProfile) && !CurFn->hasFnAttribute(llvm::Attribute::SkipProfile)) { auto AL = ApplyDebugLocation::CreateArtificial(*this); - PGO.emitCounterSetOrIncrement(Builder, S, StepV); + PGO.emitCounterSetOrIncrement(Builder, S, UseSkipPath, UseBoth, StepV); } PGO.setCurrentStmt(S); } diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp index 069469e3de856b..aefd53e12088b4 100644 --- a/clang/lib/CodeGen/CodeGenPGO.cpp +++ b/clang/lib/CodeGen/CodeGenPGO.cpp @@ -1138,6 +1138,19 @@ void CodeGenPGO::emitCounterRegionMapping(const Decl *D) { if (CoverageMapping.empty()) return; + // Scan max(FalseCnt) and update NumRegionCounters. + unsigned MaxNumCounters = NumRegionCounters; + for (const auto [_, V] : *RegionCounterMap) { +auto HasCounters = V.getIsCounterPair(); +assert((!HasCounters.first || +MaxNumCounters > (V.first & CounterPair::Mask)) && + "TrueCnt should not be reassigned"); +if (HasCounters.second) + MaxNumCounters = + std::max(MaxNumCounters, (V.second & CounterPair::Mask) + 1); + } + NumRegionCounters = MaxNumCounters; + CGM.getCoverageMapping()->addFunctionMappingRecord( FuncNameVar, FuncName, FunctionHash, CoverageMapping); } @@ -1193,11 +1206,25 @@ std::pair CodeGenPGO::getIsCounterPair(const Stmt *S) const { } void CodeGenPGO::emitCounterSetOrIncrement(CGBuilderTy &Builder, const Stmt *S, + bool UseSkipPath, bool UseBoth, llvm::Value *StepV) { - if (!RegionCounterMap || !Builder.GetInsertBlock()) + if (!RegionCounterMap) return; - unsigned Counter = (*RegionCounterMap)[S].first; + unsigned Counter; + auto &TheMap = (*RegionCounterMap)[S]; + auto IsCounter = TheMap.getIsCounterPair(); + if (!UseSkipPath) { +assert(IsCounter.first); +Counter = (TheMap.first & CounterPair::Mask); + } else { +if (!IsCounter.second) + return; +Counter = (TheMap.second & CounterPair::Mask); + } + + if (!Builder.GetInsertBlock()) +return; // Make sure that pointer to
[llvm-branch-commits] [clang] [llvm] [Coverage] Make additional counters available for BranchRegion. NFC. (PR #112730)
https://github.com/chapuni edited https://github.com/llvm/llvm-project/pull/112730 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [llvm] [Flang] Move runtime library files to flang-rt. NFC (PR #110298)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/110298 ___ 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] [flang] [lld] [llvm] [Flang] LLVM_ENABLE_RUNTIMES=FortranRuntime (PR #110217)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/110217 ___ 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] [flang] [lld] [llvm] [Flang] LLVM_ENABLE_RUNTIMES=FortranRuntime (PR #110217)
@@ -11,8 +11,11 @@ using namespace Fortran::parser::literals; + Meinersbur wrote: Removed whitespace change. Thank you. https://github.com/llvm/llvm-project/pull/110217 ___ 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] [flang] [lld] [llvm] [Flang] LLVM_ENABLE_RUNTIMES=FortranRuntime (PR #110217)
@@ -24,7 +24,7 @@ list(INSERT CMAKE_MODULE_PATH 0 # We order libraries to mirror roughly how they are layered, except that compiler-rt can depend # on libc++, so we put it after. set(LLVM_DEFAULT_RUNTIMES "libc;libunwind;libcxxabi;pstl;libcxx;compiler-rt;openmp;offload") -set(LLVM_SUPPORTED_RUNTIMES "${LLVM_DEFAULT_RUNTIMES};llvm-libgcc") +set(LLVM_SUPPORTED_RUNTIMES "${LLVM_DEFAULT_RUNTIMES};llvm-libgcc;flang-rt") Meinersbur wrote: flang is not part of the default build, so `LLVM_ENABLE_PROJECTS=all LLVM_ENABLE_RUNTIMES=all` would yield an error. https://github.com/llvm/llvm-project/pull/110217 ___ 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] [sanitizer] Add TryMemCpy (PR #112668)
@@ -325,6 +325,44 @@ bool IsAccessibleMemoryRange(uptr beg, uptr size) { return true; } +bool TryMemCpy(void *dest, const void *src, uptr n) { + int sock_pair[2]; + if (pipe(sock_pair)) +return false; + + auto cleanup = at_scope_exit([&]() { +internal_close(sock_pair[0]); +internal_close(sock_pair[1]); + }); + + SetNonBlock(sock_pair[0]); fmayer wrote: We need to handle EAGAIN if we set Nonblock https://github.com/llvm/llvm-project/pull/112668 ___ 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] [sanitizer] Add TryMemCpy (PR #112668)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/112668 ___ 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] [sanitizer] Add TryMemCpy (PR #112668)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/112668 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits