[clang] [Clang] Fix __is_trivially_equality_comparable returning true with ineligebile defaulted overloads (PR #93113)

2024-06-29 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

> > > @ZequanWu I can't successfully build your reproducer with clang trunk. 
> > > Would it be possible to provide the full test case or a fully reduced one?
> > 
> > 
> > Because I reverted this change at 
> > [567b2c6](https://github.com/llvm/llvm-project/commit/567b2c608c307c097315dd5ec4d6a5bbcddf898d),
> >  so it no longer crashes. If you recommit this or checkout to 
> > [5b36348](https://github.com/llvm/llvm-project/commit/5b363483cf2461617fbb2449491c9914811c8d53),
> >  you can repro the crash.
> 
> No, I mean it isn't a well-formed program. There are semicolons missing after 
> class definitions.

That's caused by creduce but it shouldn't matter (clang shouldn't crash due to 
syntax errors). I attached the original crash source here as creduce is still 
running. The command to repro is same as above.
[rtp_transmission_manager-8cce12.txt](https://github.com/user-attachments/files/16041931/rtp_transmission_manager-8cce12.txt)



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


[clang] [Clang] Fix __is_trivially_equality_comparable returning true with ineligebile defaulted overloads (PR #93113)

2024-06-29 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

> @ZequanWu I can't successfully build your reproducer with clang trunk. Would 
> it be possible to provide the full test case or a fully reduced one?

Because I reverted this change at 
https://github.com/llvm/llvm-project/commit/567b2c608c307c097315dd5ec4d6a5bbcddf898d,
 so it no longer crashes. If you recommit this or checkout to 
5b363483cf2461617fbb2449491c9914811c8d53, you can repro the crash.

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


[clang] [Clang] Fix __is_trivially_equality_comparable returning true with ineligebile defaulted overloads (PR #93113)

2024-06-28 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

I have a partially reduced repro:
```
$ clang++ "-cc1" "-triple" "arm64-apple-macosx10.15.0" 
"-Wundef-prefix=TARGET_OS_" "-Werror=undef-prefix" 
"-Wdeprecated-objc-isa-usage" "-Werror=deprecated-objc-isa-usage" 
"-emit-llvm-bc" "-flto=thin" "-flto-unit" "-disable-free" 
"-clear-ast-before-backend" "-main-file-name" "rtp_transmission_manager.cc" 
"-mrelocation-model" "pic" "-pic-level" "2" "-fmerge-all-constants" 
"-fno-delete-null-pointer-checks" "-mframe-pointer=non-leaf" 
"-relaxed-aliasing" "-ffp-contract=off" "-fno-rounding-math" 
"-target-sdk-version=14.0" "-fcompatibility-qualified-id-block-type-checking" 
"-fvisibility-inlines-hidden-static-local-var" 
"-fbuiltin-headers-in-system-modules" "-fdefine-target-os-macros" "-target-cpu" 
"apple-m1" "-target-feature" "+zcm" "-target-feature" "+zcz" "-target-feature" 
"+v8.4a" "-target-feature" "+aes" "-target-feature" "+crc" "-target-feature" 
"+dotprod" "-target-feature" "+complxnum" "-target-feature" "+fp-armv8" 
"-target-feature" "+fullfp16" "-target-feature" "+fp16fml" "-target-feature" 
"+jsconv" "-target-feature" "+lse" "-target-feature" "+pauth" "-target-feature" 
"+perfmon" "-target-feature" "+predres" "-target-feature" "+ras" 
"-target-feature" "+rcpc" "-target-feature" "+rdm" "-target-feature" "+sb" 
"-target-feature" "+sha2" "-target-feature" "+sha3" "-target-feature" "+neon" 
"-target-feature" "+ssbs" "-target-abi" "darwinpcs" 
"-debug-info-kind=constructor" "-dwarf-version=4" "-debugger-tuning=lldb" 
"-mllvm" "-generate-arange-section" 
"-fdebug-compilation-dir=/Volumes/Work/s/w/ir/cache/builder/src/out/Release" 
"-target-linker-version" "1053.12"  
"-fcoverage-compilation-dir=/Volumes/Work/s/w/ir/cache/builder/src/out/Release" 
"-nostdinc++" "-D" "OFFICIAL_BUILD" "-D" "__STDC_CONSTANT_MACROS" "-D" 
"__STDC_FORMAT_MACROS" "-D" "_FORTIFY_SOURCE=2" "-D" 
"_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE" "-D" "__ARM_NEON__=1" 
"-D" "CR_XCODE_VERSION=1500" "-D" 
"CR_CLANG_REVISION=\"llvmorg-19-init-15776-ge48c4011-0\"" "-D" 
"_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS" "-D" 
"_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS" "-D" 
"CR_LIBCXX_REVISION=09b99fd8ab300c93ff7b8df6688cafb27bd3db28" "-D" "NDEBUG" 
"-D" "NVALGRIND" "-D" "DYNAMIC_ANNOTATIONS_ENABLED=0" "-D" 
"WEBRTC_ENABLE_PROTOBUF=1" "-D" "WEBRTC_STRICT_FIELD_TRIALS=0" "-D" 
"RTC_ENABLE_VP9" "-D" "RTC_ENABLE_H265" "-D" 
"RTC_DAV1D_IN_INTERNAL_DECODER_FACTORY" "-D" "WEBRTC_HAVE_SCTP" "-D" 
"ENABLE_EXTERNAL_AUTH" "-D" "WEBRTC_USE_H264" "-D" "HAVE_WEBRTC_VIDEO" "-D" 
"LOGGING_INSIDE_WEBRTC" "-D" "WEBRTC_ARCH_ARM64" "-D" "WEBRTC_HAS_NEON" "-D" 
"RTC_USE_PERFETTO" "-D" "WEBRTC_LIBRARY_IMPL" "-D" "WEBRTC_ENABLE_AVX2" "-D" 
"WEBRTC_CHROMIUM_BUILD" "-D" "WEBRTC_POSIX" "-D" "WEBRTC_MAC" "-D" 
"ABSL_ALLOCATOR_NOTHROW=1" "-D" "LIBYUV_DISABLE_LSX" "-D" "LIBYUV_DISABLE_LASX" 
"-D" "UNSAFE_BUFFERS_BUILD" "-D" "PROTOBUF_ALLOW_DEPRECATED=1" "-O2" "-Wall" 
"-Wextra" "-Wimplicit-fallthrough" "-Wextra-semi" 
"-Wunreachable-code-aggressive" "-Wthread-safety" "-Wunguarded-availability" 
"-Wno-missing-field-initializers" "-Wno-unused-parameter" "-Wno-psabi" 
"-Wloop-analysis" "-Wno-unneeded-internal-declaration" 
"-Wno-cast-function-type" "-Wno-ignored-pragma-optimize" 
"-Wno-deprecated-builtins" "-Wno-deprecated-this-capture" 
"-Wno-invalid-offsetof" "-Wno-vla-extension" 
"-Wno-thread-safety-reference-return" "-Wshadow" "-Werror" 
"-Wno-profile-instr-unprofiled" "-Wno-profile-instr-out-of-date" 
"-Wno-backend-plugin" "-Wheader-hygiene" "-Wstring-conversion" 
"-Wtautological-overlap-compare" "-Wexit-time-destructors" 
"-Wglobal-constructors" "-Wno-shadow" "-Wctad-maybe-unsupported" 
"-Wenum-compare-conditional" "-Wno-c++11-narrowing-const-reference" 
"-Wno-missing-template-arg-list-after-template-kw" "-Wno-trigraphs" 
"-std=c++20" "-fdeprecated-macro" "-ferror-limit" "19" "-fvisibility=hidden" 
"-fvisibility-inlines-hidden" "-stack-protector" "1" 
"-ftrivial-auto-var-init=pattern" "-fblocks" 
"-fencode-extended-block-signature" "-fno-rtti" 
"-fregister-global-dtors-with-atexit" "-fgnuc-version=4.2.1" 
"-fno-implicit-modules" "-fskip-odr-check-in-gmf" "-fno-sized-deallocation" 
"-fmax-type-align=16" "-Qn" "-fcolor-diagnostics" "-vectorize-loops" 
"-vectorize-slp" "-debug-info-kind=limited" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" 
"-x" "c++" rtp_transmission_manager.cpp
```
I have to rename the attached file to `*.txt` as github doesn't allow .cpp 
suffix.
[rtp_transmission_manager.txt](https://github.com/user-attachments/files/16033951/rtp_transmission_manager.txt)


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


[clang] Revert "[Clang] Fix __is_trivially_equality_comparable returning true with ineligebile defaulted overloads" (PR #97002)

2024-06-27 Thread Zequan Wu via cfe-commits

https://github.com/ZequanWu edited 
https://github.com/llvm/llvm-project/pull/97002
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Fix __is_trivially_equality_comparable returning true with ineligebile defaulted overloads (PR #93113)

2024-06-27 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

Reverting for now as this also breaks LLVM CI builder.

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


[clang] Revert "[Clang] Fix __is_trivially_equality_comparable returning true with ineligebile defaulted overloads" (PR #97002)

2024-06-27 Thread Zequan Wu via cfe-commits

https://github.com/ZequanWu closed 
https://github.com/llvm/llvm-project/pull/97002
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Revert "[Clang] Fix __is_trivially_equality_comparable returning true with ineligebile defaulted overloads" (PR #97002)

2024-06-27 Thread Zequan Wu via cfe-commits

https://github.com/ZequanWu created 
https://github.com/llvm/llvm-project/pull/97002

Reverts llvm/llvm-project#93113

>From 62d7d5611e70682f8743e7322e34204480ffe189 Mon Sep 17 00:00:00 2001
From: Zequan Wu 
Date: Fri, 28 Jun 2024 00:36:19 -0400
Subject: [PATCH] =?UTF-8?q?Revert=20"[Clang]=20Fix=20=5F=5Fis=5Ftrivially?=
 =?UTF-8?q?=5Fequality=5Fcomparable=20returning=20true=20with=20in?=
 =?UTF-8?q?=E2=80=A6"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This reverts commit 5b363483cf2461617fbb2449491c9914811c8d53.
---
 clang/docs/ReleaseNotes.rst|  5 +-
 clang/include/clang/AST/Type.h |  3 ++
 clang/lib/AST/Type.cpp | 60 +++
 clang/lib/Sema/SemaExprCXX.cpp | 78 +-
 clang/test/SemaCXX/type-traits.cpp | 43 
 5 files changed, 65 insertions(+), 124 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7ebfc87144269..da967fcdda808 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -104,7 +104,7 @@ ABI Changes in This Version
   ifuncs. Its purpose was to preserve backwards compatibility when the ".ifunc"
   suffix got removed from the name mangling. The alias interacts badly with
   GlobalOpt (see the issue #96197).
-
+  
 - Fixed Microsoft name mangling for auto non-type template arguments of pointer
   type for MSVC 1920+. This change resolves incompatibilities with code 
compiled
   by MSVC 1920+ but will introduce incompatibilities with code compiled by
@@ -740,9 +740,6 @@ Bug Fixes in This Version
   negatives where the analysis failed to detect unchecked access to guarded
   data.
 
-- ``__is_trivially_equality_comparable`` no longer returns true for types which
-  have a constrained defaulted comparison operator (#GH89293).
-
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index a98899f7f4222..62836ec5c6312 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -1142,6 +1142,9 @@ class QualType {
   /// Return true if this is a trivially relocatable type.
   bool isTriviallyRelocatableType(const ASTContext ) const;
 
+  /// Return true if this is a trivially equality comparable type.
+  bool isTriviallyEqualityComparableType(const ASTContext ) const;
+
   /// Returns true if it is a class and it might be dynamic.
   bool mayBeDynamicClass() const;
 
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index cc535aba4936e..d8b885870de3a 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2815,6 +2815,66 @@ bool QualType::isTriviallyRelocatableType(const 
ASTContext ) const {
   }
 }
 
+static bool
+HasNonDeletedDefaultedEqualityComparison(const CXXRecordDecl *Decl) {
+  if (Decl->isUnion())
+return false;
+  if (Decl->isLambda())
+return Decl->isCapturelessLambda();
+
+  auto IsDefaultedOperatorEqualEqual = [&](const FunctionDecl *Function) {
+return Function->getOverloadedOperator() ==
+   OverloadedOperatorKind::OO_EqualEqual &&
+   Function->isDefaulted() && Function->getNumParams() > 0 &&
+   (Function->getParamDecl(0)->getType()->isReferenceType() ||
+Decl->isTriviallyCopyable());
+  };
+
+  if (llvm::none_of(Decl->methods(), IsDefaultedOperatorEqualEqual) &&
+  llvm::none_of(Decl->friends(), [&](const FriendDecl *Friend) {
+if (NamedDecl *ND = Friend->getFriendDecl()) {
+  return ND->isFunctionOrFunctionTemplate() &&
+ IsDefaultedOperatorEqualEqual(ND->getAsFunction());
+}
+return false;
+  }))
+return false;
+
+  return llvm::all_of(Decl->bases(),
+  [](const CXXBaseSpecifier ) {
+if (const auto *RD = 
BS.getType()->getAsCXXRecordDecl())
+  return HasNonDeletedDefaultedEqualityComparison(RD);
+return true;
+  }) &&
+ llvm::all_of(Decl->fields(), [](const FieldDecl *FD) {
+   auto Type = FD->getType();
+   if (Type->isArrayType())
+ Type = 
Type->getBaseElementTypeUnsafe()->getCanonicalTypeUnqualified();
+
+   if (Type->isReferenceType() || Type->isEnumeralType())
+ return false;
+   if (const auto *RD = Type->getAsCXXRecordDecl())
+ return HasNonDeletedDefaultedEqualityComparison(RD);
+   return true;
+ });
+}
+
+bool QualType::isTriviallyEqualityComparableType(
+const ASTContext ) const {
+  QualType CanonicalType = getCanonicalType();
+  if (CanonicalType->isIncompleteType() || CanonicalType->isDependentType() ||
+  CanonicalType->isEnumeralType() || CanonicalType->isArrayType())
+return false;
+
+  if (const auto *RD = CanonicalType->getAsCXXRecordDecl()) {
+if (!HasNonDeletedDefaultedEqualityComparison(RD))
+  return 

[clang] [Clang] Fix __is_trivially_equality_comparable returning true with ineligebile defaulted overloads (PR #93113)

2024-06-27 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

This causes clang to crash when building chromium:
```
Assertion failed: (Loc.isValid() && "point of instantiation must be valid!"), 
function setPointOfInstantiation, file DeclTemplate.h, line 1938.
PLEASE submit a bug report to https://crbug.com in the Tools>LLVM component, 
run tools/clang/scripts/process_crashreports.py (only if inside Google) to 
upload crash related files, and include the crash backtrace, preprocessed 
source, and associated run script.
Stack dump:
0.  Program arguments: 
../../third_party/llvm-build/Release+Asserts/bin/clang++ -MMD -MF 
obj/third_party/webrtc/pc/rtp_transmission_manager/rtp_transmission_manager.o.d 
-DOFFICIAL_BUILD -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS 
-D_FORTIFY_SOURCE=2 -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE 
-D__ARM_NEON__=1 -DCR_XCODE_VERSION=1500 
-DCR_CLANG_REVISION=\"llvmorg-19-init-15776-ge48c4011-0\" 
-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS 
-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS 
-DCR_LIBCXX_REVISION=09b99fd8ab300c93ff7b8df6688cafb27bd3db28 -DNDEBUG 
-DNVALGRIND -DDYNAMIC_ANNOTATIONS_ENABLED=0 -DWEBRTC_ENABLE_PROTOBUF=1 
-DWEBRTC_STRICT_FIELD_TRIALS=0 -DRTC_ENABLE_VP9 -DRTC_ENABLE_H265 
-DRTC_DAV1D_IN_INTERNAL_DECODER_FACTORY -DWEBRTC_HAVE_SCTP 
-DENABLE_EXTERNAL_AUTH -DWEBRTC_USE_H264 -DHAVE_WEBRTC_VIDEO 
-DLOGGING_INSIDE_WEBRTC -DWEBRTC_ARCH_ARM64 -DWEBRTC_HAS_NEON 
-DRTC_USE_PERFETTO -DWEBRTC_LIBRARY_IMPL -DWEBRTC_ENABLE_AVX2 
-DWEBRTC_CHROMIUM_BUILD -DWEBRTC_POSIX -DWEBRTC_MAC -DABSL_ALLOCATOR_NOTHROW=1 
-DLIBYUV_DISABLE_LSX -DLIBYUV_DISABLE_LASX -I../.. -Igen 
-I../../buildtools/third_party/libc++ -I../../third_party/webrtc_overrides 
-I../../third_party/webrtc -Igen/third_party/webrtc 
-I../../third_party/abseil-cpp -I../../third_party/perfetto/include 
-Igen/third_party/perfetto/build_config -Igen/third_party/perfetto 
-I../../third_party/libyuv/include 
-I../../base/allocator/partition_allocator/src 
-Igen/base/allocator/partition_allocator/src 
-I../../third_party/boringssl/src/include -I../../third_party/protobuf/src 
-Igen/protoc_out -Wall -Wextra -Wimplicit-fallthrough -Wextra-semi 
-Wunreachable-code-aggressive -Wthread-safety -Wunguarded-availability 
-Wno-missing-field-initializers -Wno-unused-parameter -Wno-psabi 
-Wloop-analysis -Wno-unneeded-internal-declaration -Wno-cast-function-type 
-Wno-ignored-pragma-optimize -Wno-deprecated-builtins 
-Wno-deprecated-this-capture -Wno-invalid-offsetof -Wno-vla-extension 
-Wno-thread-safety-reference-return -Wshadow -Werror 
-fno-delete-null-pointer-checks -fno-ident -fno-strict-aliasing 
-fstack-protector -fcolor-diagnostics -fmerge-all-constants 
-fno-sized-deallocation -fcrash-diagnostics-dir=../../tools/clang/crashreports 
-mllvm -instcombine-lower-dbg-declare=0 -mllvm 
-split-threshold-for-reg-with-hint=0 -ffp-contract=off -flto=thin 
-fsplit-lto-unit -mllvm -inlinehint-threshold=360 -fwhole-program-vtables 
-fcomplete-member-pointers --target=arm64-apple-macos -mno-outline 
-no-canonical-prefixes -ftrivial-auto-var-init=pattern -O2 -fno-math-errno 
-fno-omit-frame-pointer -fno-standalone-debug -g2 -gdwarf-aranges -Xclang 
-debug-info-kind=limited -isysroot 
../../build/mac_files/xcode_binaries/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk
 -mmacos-version-min=10.15 
-fprofile-use=../../chrome/build/pgo_profiles/chrome-mac-arm-main-1719532733-22346236a77819af9911adca57b0117b3bed6727-07d9695ebcbe87f7704e609d7c4e5ad21ca1a5d6.profdata
 -Wno-profile-instr-unprofiled -Wno-profile-instr-out-of-date 
-Wno-backend-plugin -fvisibility=hidden -Wheader-hygiene -Wstring-conversion 
-Wtautological-overlap-compare -Xclang -add-plugin -Xclang find-bad-constructs 
-Xclang -plugin-arg-find-bad-constructs -Xclang span-ctor-from-string-literal 
-Xclang -plugin-arg-find-bad-constructs -Xclang 
raw-ref-template-as-trivial-member -Xclang -plugin-arg-find-bad-constructs 
-Xclang check-stack-allocated -Xclang -plugin-arg-find-bad-constructs -Xclang 
check-allow-auto-typedefs-better-nested -Xclang -add-plugin -Xclang 
raw-ptr-plugin -Xclang -plugin-arg-raw-ptr-plugin -Xclang 
check-raw-ptr-to-stack-allocated -Xclang -plugin-arg-raw-ptr-plugin -Xclang 
disable-check-raw-ptr-to-stack-allocated-error -Xclang 
-plugin-arg-raw-ptr-plugin -Xclang raw-ptr-exclude-path=/renderer/ -Xclang 
-plugin-arg-raw-ptr-plugin -Xclang 
raw-ptr-exclude-path=../../third_party/blink/public/web/ -Xclang 
-plugin-arg-raw-ptr-plugin -Xclang raw-ptr-exclude-path=../../third_party/dawn/ 
-DUNSAFE_BUFFERS_BUILD -Xclang -add-plugin -Xclang unsafe-buffers -Xclang 
-plugin-arg-unsafe-buffers -Xclang ../../build/config/unsafe_buffers_paths.txt 
-Wexit-time-destructors -Wglobal-constructors -Wno-shadow 
-Wctad-maybe-unsupported -DPROTOBUF_ALLOW_DEPRECATED=1 
-Wenum-compare-conditional -Wno-c++11-narrowing-const-reference 
-Wno-missing-template-arg-list-after-template-kw -std=c++20 -Wno-trigraphs 
-fno-exceptions -fno-rtti -nostdinc++ 

[clang] Add option to avoid generating coverage mappings for unused functions (PR #92582)

2024-05-23 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

> The problem that this solves is related to binary size. In situations where a 
> large C API is in generated code but a small part of the API is used, the 
> size of __llvm_prf_names and __llvm_cov_fun sections can be prohibitively 
> large. This flag offers a way to reduce binary size in this case assuming you 
> aren't concerned with coverage of non-emitted code.

There's some ways to reduce the instrumented binary size on code coverage.
1. Single byte counter: 
https://discourse.llvm.org/t/rfc-single-byte-counters-for-source-based-code-coverage/75685.
 If you don't care about the exact number of execution of of covered regions 
and just want to know if those regions ever got executed, this is a good option 
for it. This makes each counter 1 byte instead of 8 bytes.
2. Binary profile correlation: 
https://discourse.llvm.org/t/rfc-add-binary-profile-correlation-to-not-load-profile-metadata-sections-into-memory-at-runtime/74565.
 With this mode, it still generates the same `__llvm_prf_names` and 
`__llvm_prf_data` sections, but they can be stripped away before binary starts 
running. At merging stage, you need to provide the unstripped version of the 
binary to restore the information in those stripped sections. Basically, this 
reduces the stripped instrumented-binary size and raw profiles size.

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


[clang] Add option to avoid generating coverage mappings for unused functions (PR #92582)

2024-05-22 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

I think the main purpose for emitting coverage mapping for un-emitted functions 
is to tell llvm-cov that those functions are not executed at all, so it shows 
execution count 0 for them instead of not-covered.

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


[clang] Reapply "[Clang][CWG1815] Support lifetime extension of temporary created by aggregate initialization using a default member initializer" (PR #92527)

2024-05-21 Thread Zequan Wu via cfe-commits


@@ -27,6 +27,80 @@ class MemInit {
   C m = s;
 };
 
+namespace std {
+typedef decltype(sizeof(int)) size_t;
+
+// libc++'s implementation
+template  class initializer_list {
+  const _E *__begin_;
+  size_t __size_;
+
+  initializer_list(const _E *__b, size_t __s) : __begin_(__b), __size_(__s) {}
+
+public:
+  typedef _E value_type;
+  typedef const _E 
+  typedef const _E _reference;
+  typedef size_t size_type;
+
+  typedef const _E *iterator;
+  typedef const _E *const_iterator;
+
+  initializer_list() : __begin_(nullptr), __size_(0) {}
+
+  size_t size() const { return __size_; }
+  const _E *begin() const { return __begin_; }
+  const _E *end() const { return __begin_ + __size_; }
+};
+} // namespace std
+
+#if __cplusplus >= 201703L
+namespace test_rebuild {

ZequanWu wrote:

Thanks!

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


[clang] [Clang][CWG1815] Support lifetime extension of temporary created by aggregate initialization using a default member initializer (PR #87933)

2024-05-16 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

Here's a smaller repro of the `-Wuninitialized` warning:
```
int TestBody_got;
namespace std {
template  struct integral_constant {
  static const int value = __v;
};
template  using enable_if_t = _Tp;
template  class initializer_list {};
template 
constexpr bool IsTypeOrDerived = integral_constant<__is_same(int, int)>::value;
template 
using EnableIf = enable_if_t;
template 
using EnableIfIsType = EnableIf, T>;
template  class Vector {
public:
  Vector(initializer_list);
};
template  Vector(Ts...) -> Vector;
class ProgramBuilder {
public:
  template  EnableIfIsType *create(ARGS);
};
using TestHelper = ProgramBuilder;
struct TypeTest : TestHelper {
  int *str_f16 = create(Vector{0});
  TypeTest() {}
};
class TypeTest_Element_Test : TypeTest {
  void TestBody();
};
}
void std::TypeTest_Element_Test::TestBody() {
  int *expect = str_f16;
  _got != expect;
}
$ clang reduce.cpp -std=c++20 -fsyntax-only -Wuninitialized 
-Wno-unused-comparison
reduce.cpp:34:20: warning: variable 'expect' is uninitialized when used here 
[-Wuninitialized]
   34 |   _got != expect;
  |^~
reduce.cpp:33:14: note: initialize the variable 'expect' to silence this warning
   33 |   int *expect = str_f16;
  |  ^
  |   = nullptr
1 warning generated.
```

Can you verify if this is a false positive or not? If it's a false positive and 
would take a while to fix, can you revert this commit?

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


[clang] [Clang][CWG1815] Support lifetime extension of temporary created by aggregate initialization using a default member initializer (PR #87933)

2024-05-15 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

Can we revert this change while you are investigating if this fix is not 
trivial?

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


[clang] [Clang][CWG1815] Support lifetime extension of temporary created by aggregate initialization using a default member initializer (PR #87933)

2024-05-15 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

Great, I just finished a creduce run with renaming pass disabled, but yours is 
short.

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


[clang] Allow passing creduce options through creduce-clang-crash.py (PR #92141)

2024-05-14 Thread Zequan Wu via cfe-commits

https://github.com/ZequanWu closed 
https://github.com/llvm/llvm-project/pull/92141
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Allow passing creduce options through creduce-clang-crash.py (PR #92141)

2024-05-14 Thread Zequan Wu via cfe-commits

https://github.com/ZequanWu updated 
https://github.com/llvm/llvm-project/pull/92141

>From 39d996deffc9d77c28f9f43c2f2ba4b114dd864f Mon Sep 17 00:00:00 2001
From: Zequan Wu 
Date: Tue, 14 May 2024 12:08:15 -0400
Subject: [PATCH 1/2] Allow passing creduce options through
 creduce-clang-crash.py

---
 clang/utils/creduce-clang-crash.py | 29 ++---
 1 file changed, 10 insertions(+), 19 deletions(-)

diff --git a/clang/utils/creduce-clang-crash.py 
b/clang/utils/creduce-clang-crash.py
index 4d0c8224d8b49..e2c999196f36c 100755
--- a/clang/utils/creduce-clang-crash.py
+++ b/clang/utils/creduce-clang-crash.py
@@ -1,5 +1,6 @@
 #!/usr/bin/env python3
 """Calls C-Reduce to create a minimal reproducer for clang crashes.
+Unknown arguments are treated at creduce options.
 
 Output files:
   *.reduced.sh -- crash reproducer with minimal arguments
@@ -70,7 +71,7 @@ def write_to_script(text, filename):
 
 
 class Reduce(object):
-def __init__(self, crash_script, file_to_reduce, core_number):
+def __init__(self, crash_script, file_to_reduce, creduce_flags):
 crash_script_name, crash_script_ext = os.path.splitext(crash_script)
 file_reduce_name, file_reduce_ext = os.path.splitext(file_to_reduce)
 
@@ -83,8 +84,7 @@ def __init__(self, crash_script, file_to_reduce, core_number):
 self.clang_args = []
 self.expected_output = []
 self.needs_stack_trace = False
-self.creduce_flags = ["--tidy"]
-self.creduce_flags = ["--n", str(core_number)]
+self.creduce_flags = ["--tidy"] + creduce_flags
 
 self.read_clang_args(crash_script, file_to_reduce)
 self.read_expected_output()
@@ -412,13 +412,13 @@ def reduce_clang_args(self):
 print("Reduced command:", reduced_cmd)
 
 def run_creduce(self):
+full_creduce_cmd = (
+[creduce_cmd] + self.creduce_flags + [self.testfile, 
self.file_to_reduce]
+)
 print("\nRunning C-Reduce...")
+verbose_print(quote_cmd(full_creduce_cmd))
 try:
-p = subprocess.Popen(
-[creduce_cmd]
-+ self.creduce_flags
-+ [self.testfile, self.file_to_reduce]
-)
+p = subprocess.Popen(full_creduce_cmd)
 p.communicate()
 except KeyboardInterrupt:
 # Hack to kill C-Reduce because it jumps into its own pgid
@@ -458,26 +458,17 @@ def main():
 help="The path to the `creduce` executable. "
 "Required if `creduce` is not in PATH environment.",
 )
-parser.add_argument(
-"--n",
-dest="core_number",
-type=int,
-default=max(4, multiprocessing.cpu_count() // 2),
-help="Number of cores to use.",
-)
 parser.add_argument("-v", "--verbose", action="store_true")
-args = parser.parse_args()
-
+args, creduce_flags = parser.parse_known_args()
 verbose = args.verbose
 llvm_bin = os.path.abspath(args.llvm_bin) if args.llvm_bin else None
 creduce_cmd = check_cmd("creduce", None, args.creduce)
 clang_cmd = check_cmd("clang", llvm_bin, args.clang)
-core_number = args.core_number
 
 crash_script = check_file(args.crash_script[0])
 file_to_reduce = check_file(args.file_to_reduce[0])
 
-r = Reduce(crash_script, file_to_reduce, core_number)
+r = Reduce(crash_script, file_to_reduce, creduce_flags)
 
 r.simplify_clang_args()
 r.write_interestingness_test()

>From 52653f74dd05801d51746edcbe3194d2e804ec07 Mon Sep 17 00:00:00 2001
From: Zequan Wu 
Date: Tue, 14 May 2024 12:50:34 -0400
Subject: [PATCH 2/2] restore the behaviour of using max(4, cpu_count/2) if --n
 flag is not given

---
 clang/utils/creduce-clang-crash.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/utils/creduce-clang-crash.py 
b/clang/utils/creduce-clang-crash.py
index e2c999196f36c..db4a3435a3aef 100755
--- a/clang/utils/creduce-clang-crash.py
+++ b/clang/utils/creduce-clang-crash.py
@@ -468,6 +468,9 @@ def main():
 crash_script = check_file(args.crash_script[0])
 file_to_reduce = check_file(args.file_to_reduce[0])
 
+if "--n" not in creduce_flags:
+creduce_flags += ["--n", str(max(4, multiprocessing.cpu_count() // 2))]
+
 r = Reduce(crash_script, file_to_reduce, creduce_flags)
 
 r.simplify_clang_args()

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


[clang] Allow passing creduce options through creduce-clang-crash.py (PR #92141)

2024-05-14 Thread Zequan Wu via cfe-commits

https://github.com/ZequanWu created 
https://github.com/llvm/llvm-project/pull/92141

This change allows us to pass creduce options to creduce-clang-crash.py script. 
With this, `--n` is no longer needed to specify the number of cores, so removed 
the flag.

The motivation is 
https://github.com/llvm/llvm-project/pull/87933#issuecomment-2109463497 
suggests that disabling creduce renaming passes helps people to further reduce 
crash manually.

>From 39d996deffc9d77c28f9f43c2f2ba4b114dd864f Mon Sep 17 00:00:00 2001
From: Zequan Wu 
Date: Tue, 14 May 2024 12:08:15 -0400
Subject: [PATCH] Allow passing creduce options through creduce-clang-crash.py

---
 clang/utils/creduce-clang-crash.py | 29 ++---
 1 file changed, 10 insertions(+), 19 deletions(-)

diff --git a/clang/utils/creduce-clang-crash.py 
b/clang/utils/creduce-clang-crash.py
index 4d0c8224d8b49..e2c999196f36c 100755
--- a/clang/utils/creduce-clang-crash.py
+++ b/clang/utils/creduce-clang-crash.py
@@ -1,5 +1,6 @@
 #!/usr/bin/env python3
 """Calls C-Reduce to create a minimal reproducer for clang crashes.
+Unknown arguments are treated at creduce options.
 
 Output files:
   *.reduced.sh -- crash reproducer with minimal arguments
@@ -70,7 +71,7 @@ def write_to_script(text, filename):
 
 
 class Reduce(object):
-def __init__(self, crash_script, file_to_reduce, core_number):
+def __init__(self, crash_script, file_to_reduce, creduce_flags):
 crash_script_name, crash_script_ext = os.path.splitext(crash_script)
 file_reduce_name, file_reduce_ext = os.path.splitext(file_to_reduce)
 
@@ -83,8 +84,7 @@ def __init__(self, crash_script, file_to_reduce, core_number):
 self.clang_args = []
 self.expected_output = []
 self.needs_stack_trace = False
-self.creduce_flags = ["--tidy"]
-self.creduce_flags = ["--n", str(core_number)]
+self.creduce_flags = ["--tidy"] + creduce_flags
 
 self.read_clang_args(crash_script, file_to_reduce)
 self.read_expected_output()
@@ -412,13 +412,13 @@ def reduce_clang_args(self):
 print("Reduced command:", reduced_cmd)
 
 def run_creduce(self):
+full_creduce_cmd = (
+[creduce_cmd] + self.creduce_flags + [self.testfile, 
self.file_to_reduce]
+)
 print("\nRunning C-Reduce...")
+verbose_print(quote_cmd(full_creduce_cmd))
 try:
-p = subprocess.Popen(
-[creduce_cmd]
-+ self.creduce_flags
-+ [self.testfile, self.file_to_reduce]
-)
+p = subprocess.Popen(full_creduce_cmd)
 p.communicate()
 except KeyboardInterrupt:
 # Hack to kill C-Reduce because it jumps into its own pgid
@@ -458,26 +458,17 @@ def main():
 help="The path to the `creduce` executable. "
 "Required if `creduce` is not in PATH environment.",
 )
-parser.add_argument(
-"--n",
-dest="core_number",
-type=int,
-default=max(4, multiprocessing.cpu_count() // 2),
-help="Number of cores to use.",
-)
 parser.add_argument("-v", "--verbose", action="store_true")
-args = parser.parse_args()
-
+args, creduce_flags = parser.parse_known_args()
 verbose = args.verbose
 llvm_bin = os.path.abspath(args.llvm_bin) if args.llvm_bin else None
 creduce_cmd = check_cmd("creduce", None, args.creduce)
 clang_cmd = check_cmd("clang", llvm_bin, args.clang)
-core_number = args.core_number
 
 crash_script = check_file(args.crash_script[0])
 file_to_reduce = check_file(args.file_to_reduce[0])
 
-r = Reduce(crash_script, file_to_reduce, core_number)
+r = Reduce(crash_script, file_to_reduce, creduce_flags)
 
 r.simplify_clang_args()
 r.write_interestingness_test()

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


[clang] [Clang][CWG1815] Support lifetime extension of temporary created by aggregate initialization using a default member initializer (PR #87933)

2024-05-13 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

```
$ cat a.cpp
namespace std {
template  struct b {
  static const int c = a;
};
template  using e = d;
template  struct p {
  using g = f;
};
template  using i = p::g;
template  class initializer_list {};
template  using j = __remove_pointer(d);
template  using k = j;
template  constexpr bool l = b<__is_base_of(int, int)>::c;
template  using ab = e;
template  using o = ab, n>;
template  constexpr bool ad = (l && ...);
template  struct u;
template  using ae = u::g;
template  struct u {
  using g = n;
};
template  class t {
public:
  t(initializer_list);
};
namespace ag {
template  struct D;
template  struct D {
  using ah = ae...>;
  using g = i<0, ah, ah *>;
};
}
template  using r = ag::D, s...>::g;
template  t(s...) -> t, sizeof...(s)>;
class v {
public:
  template  o *w(an &&);
};
using ap = v;
struct aq : ap {
  int *ar = w(t{w(int{})});
  aq() {}
}
$ clang a.cpp
[crash]
```

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


[clang] [Clang][CWG1815] Support lifetime extension of temporary created by aggregate initialization using a default member initializer (PR #87933)

2024-05-13 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

Heads up. This causes clang to crash on some code. I'm running creduce to 
reduce the cpp source file.

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


[clang] [clang][CoverageMapping] do not emit gap when either end is an `ImplicitValueInitExpr` (PR #89564)

2024-04-22 Thread Zequan Wu via cfe-commits

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


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


[clang] [clang][CoverageMapping] do not emit gap when either end is an `ImplicitValueInitExpr` (PR #89564)

2024-04-22 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

There could be some other statements with invalid source locations (we have 
seen that before). I suggest validating both source locations inside 
`findGapAreaBetween` and returning `std::nullopt` if either of them is invalid.

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


[clang] Use timeTraceAsyncProfilerBegin for Source span (PR #83961)

2024-03-25 Thread Zequan Wu via cfe-commits


@@ -102,23 +104,24 @@ struct llvm::TimeTraceProfiler {
 llvm::get_thread_name(ThreadName);
   }
 
-  void begin(std::string Name, llvm::function_ref Detail) {
-Stack.emplace_back(ClockType::now(), TimePointType(), std::move(Name),
-   Detail());
+  TimeTraceProfilerEntry *begin(std::string Name,
+llvm::function_ref Detail,
+bool AsyncEvent = false) {
+Stack.emplace_back(std::make_unique(
+ClockType::now(), TimePointType(), std::move(Name), Detail(),
+AsyncEvent));
+return Stack.back().get();
   }
 
   void end() {
+TimeTraceProfilerEntry *E = Stack.back().get();

ZequanWu wrote:

Yeah. But usually assertions goes before use. `end()` uses `Stack.back()` which 
assumes stack is non-empty.

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


[clang] Use timeTraceAsyncProfilerBegin for Source span (PR #83961)

2024-03-25 Thread Zequan Wu via cfe-commits

https://github.com/ZequanWu edited 
https://github.com/llvm/llvm-project/pull/83961
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Use timeTraceAsyncProfilerBegin for Source span (PR #83961)

2024-03-25 Thread Zequan Wu via cfe-commits

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


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


[clang] [llvm] Use timeTraceAsyncProfilerBegin for Source span (PR #83961)

2024-03-13 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

> > > > IIUC, the approach you choose here is to let `SemaPPCallbacks` control 
> > > > the "entered file stack" and allow it to remove element (which is file) 
> > > > from middle of the internal stack in `TimeTraceProfiler`, but this 
> > > > creates async event which is not designed for this purpose.
> > > > Can we let `SemaPPCallbacks` track the last push file into the stack 
> > > > and when exit file, pop all the elements from the stack until we popped 
> > > > the last pushed file?
> > > 
> > > 
> > > As I wrote in [#56554 
> > > (comment)](https://github.com/llvm/llvm-project/issues/56554#issuecomment-1975812398),
> > >  file level span and syntax tree level span should be handled 
> > > asynchronously. So using such implementation produces incorrect trace in 
> > > other edge cases.
> > 
> > 
> > Can we choose to expose a handle (maybe an unique id for each entry) from 
> > `TimeTraceProfiler` instead of exposing the internal entry?
> 
> I think pointer to `TimeTraceProfilerEntry` is already like handle as 
> definition of the struct is not written in header file. Having another handle 
> for that seems unnecessary indirection layer to me. Or better to change the 
> name of struct?

Okay, make sense. Looks good for me.
Adding @MaskRay to review in case he has something to say.

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


[clang] [llvm] Use timeTraceAsyncProfilerBegin for Source span (PR #83961)

2024-03-12 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

> > IIUC, the approach you choose here is to let `SemaPPCallbacks` control the 
> > "entered file stack" and allow it to remove element (which is file) from 
> > middle of the internal stack in `TimeTraceProfiler`, but this creates async 
> > event which is not designed for this purpose.
> > Can we let `SemaPPCallbacks` track the last push file into the stack and 
> > when exit file, pop all the elements from the stack until we popped the 
> > last pushed file?
> 
> As I wrote in [#56554 
> (comment)](https://github.com/llvm/llvm-project/issues/56554#issuecomment-1975812398),
>  file level span and syntax tree level span should be handled asynchronously. 
> So using such implementation produces incorrect trace in other edge cases.

Can we choose to expose a handle (maybe an unique id for each entry) from 
`TimeTraceProfiler` instead of exposing the internal entry?

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


[clang] [llvm] Use timeTraceAsyncProfilerBegin for Source span (PR #83961)

2024-03-12 Thread Zequan Wu via cfe-commits


@@ -102,23 +104,24 @@ struct llvm::TimeTraceProfiler {
 llvm::get_thread_name(ThreadName);
   }
 
-  void begin(std::string Name, llvm::function_ref Detail) {
-Stack.emplace_back(ClockType::now(), TimePointType(), std::move(Name),
-   Detail());
+  TimeTraceProfilerEntry *begin(std::string Name,
+llvm::function_ref Detail,
+bool AsyncEvent = false) {
+Stack.emplace_back(std::make_unique(
+ClockType::now(), TimePointType(), std::move(Name), Detail(),
+AsyncEvent));
+return Stack.back().get();
   }
 
   void end() {
+TimeTraceProfilerEntry *E = Stack.back().get();

ZequanWu wrote:

But that's assertion after the call to `Stack.back()`.

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


[clang] [llvm] Use timeTraceAsyncProfilerBegin for Source span (PR #83961)

2024-03-11 Thread Zequan Wu via cfe-commits


@@ -132,15 +135,18 @@ struct llvm::TimeTraceProfiler {
 // happens to be the ones that don't have any currently open entries above
 // itself.
 if (llvm::none_of(llvm::drop_begin(llvm::reverse(Stack)),
-  [&](const TimeTraceProfilerEntry ) {
-return Val.Name == E.Name;
+  [&](const std::unique_ptr ) {
+return Val->Name == E.Name;
   })) {
   auto  = CountAndTotalPerName[E.Name];
   CountAndTotal.first++;
   CountAndTotal.second += Duration;
-}
+};

ZequanWu wrote:

Unnecessary change.
```suggestion
}
```

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


[clang] [llvm] Use timeTraceAsyncProfilerBegin for Source span (PR #83961)

2024-03-11 Thread Zequan Wu via cfe-commits

https://github.com/ZequanWu commented:

IIUC, the approach you choose here is to let `SemaPPCallbacks` control the 
"entered file stack" and allow it to remove element (which is file) from middle 
of the internal stack in `TimeTraceProfiler`, but this creates async event 
which is not designed for this purpose.

Can we let `SemaPPCallbacks` track the last push file into the stack and when 
exit file, pop all the elements from the stack until we popped the last pushed 
file?



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


[clang] [llvm] Use timeTraceAsyncProfilerBegin for Source span (PR #83961)

2024-03-11 Thread Zequan Wu via cfe-commits

https://github.com/ZequanWu edited 
https://github.com/llvm/llvm-project/pull/83961
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Use timeTraceAsyncProfilerBegin for Source span (PR #83961)

2024-03-11 Thread Zequan Wu via cfe-commits


@@ -102,23 +104,24 @@ struct llvm::TimeTraceProfiler {
 llvm::get_thread_name(ThreadName);
   }
 
-  void begin(std::string Name, llvm::function_ref Detail) {
-Stack.emplace_back(ClockType::now(), TimePointType(), std::move(Name),
-   Detail());
+  TimeTraceProfilerEntry *begin(std::string Name,
+llvm::function_ref Detail,
+bool AsyncEvent = false) {
+Stack.emplace_back(std::make_unique(
+ClockType::now(), TimePointType(), std::move(Name), Detail(),
+AsyncEvent));
+return Stack.back().get();
   }
 
   void end() {
+TimeTraceProfilerEntry *E = Stack.back().get();

ZequanWu wrote:

If we extract end(TimeTraceProfilerEntry ) to a separate function, probably 
want to move the assertion to here as well

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


[llvm] [clang] [clang-tools-extra] [compiler-rt] [Profile] Allow profile merging with multiple correlate files. (PR #75957)

2024-01-18 Thread Zequan Wu via cfe-commits


@@ -35,20 +36,32 @@ class InstrProfCorrelator {
   /// correlate.
   enum ProfCorrelatorKind { NONE, DEBUG_INFO, BINARY };
 
+  struct WarningCounter {

ZequanWu wrote:

Since there is 
[debate](https://github.com/llvm/llvm-project/pull/75957#discussion_r1433009581)
 about if this change is necessary at all, let's keep the change here in case 
we decided it's unnecessary.

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


[llvm] [clang-tools-extra] [compiler-rt] [clang] [Profile] Allow profile merging with multiple correlate files. (PR #75957)

2024-01-18 Thread Zequan Wu via cfe-commits


@@ -42,6 +43,21 @@ template  BuildIDRef getBuildID(const 
ELFFile ) {
   return {};
 }
 
+BuildIDRef getBuildID(const COFFObjectFile *Obj) {

ZequanWu wrote:

By that, we don't have any test for it. The test 
`compiler-rt/test/profile/Windows/instrprof-binary-correlate.c` uses it.

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


[llvm] [compiler-rt] [clang] [clang-tools-extra] [Profile] Allow profile merging with multiple correlate files. (PR #75957)

2024-01-18 Thread Zequan Wu via cfe-commits


@@ -0,0 +1,33 @@
+// Test llvm-profdata merging with multiple correlation files mixing different 
correlation modes.
+
+// RUN: %clang_pgogen -o %t.normal -mllvm --disable-vp=true 
%S/../Inputs/instrprof-debug-info-correlate-main.cpp 
%S/../Inputs/instrprof-debug-info-correlate-foo.cpp
+// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t.normal
+// RUN: llvm-profdata merge -o %t.normal.profdata %t.profraw
+
+// Compiling with different configs.
+// RUN: %clang_pgogen -o %t -mllvm --disable-vp=true 
%S/../Inputs/instrprof-debug-info-correlate-main.cpp -c -o %t-main.o

ZequanWu wrote:

Done.

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


[clang] [compiler-rt] [llvm] [clang-tools-extra] [Profile] Allow profile merging with multiple correlate files. (PR #75957)

2024-01-18 Thread Zequan Wu via cfe-commits


@@ -0,0 +1,41 @@
+// REQUIRES: target={{.*windows-msvc.*}}

ZequanWu wrote:

Yes, for mingw, `-dll` doesn't work. It uses `-shared`

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


[compiler-rt] [clang] [llvm] [clang-tools-extra] [Profile] Allow profile merging with multiple correlate files. (PR #75957)

2024-01-18 Thread Zequan Wu via cfe-commits


@@ -118,18 +118,18 @@ cl::opt ProfiledBinary(
 "profiled-binary", cl::init(""),
 cl::desc("Path to binary from which the profile was collected."),
 cl::sub(ShowSubcommand), cl::sub(MergeSubcommand));
-cl::opt DebugInfoFilename(
-"debug-info", cl::init(""),
+cl::list DebugInfoFilenames(
+"debug-info",
 cl::desc(
 "For show, read and extract profile metadata from debug info and show "
 "the functions it found. For merge, use the provided debug info to "
 "correlate the raw profile."),
 cl::sub(ShowSubcommand), cl::sub(MergeSubcommand));
-cl::opt
-BinaryFilename("binary-file", cl::init(""),
-   cl::desc("For merge, use the provided unstripped bianry to "
-"correlate the raw profile."),
-   cl::sub(MergeSubcommand));
+cl::list
+BinaryFilenames("binary-file",
+cl::desc("For merge, use the provided unstripped bianry to 
"
+ "correlate the raw profile."),
+cl::sub(MergeSubcommand));

ZequanWu wrote:

This basically adds a map with keys being BuildID and values being correlators 
(constructed from the correlate files), and uses BuildID to match raw profiles 
and correlate files. 

For now, I'll try to enable binary correlation on our side by using customized 
scripts to see if it's easier to achieve this functionality.

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


[clang] [llvm] [compiler-rt] [clang-tools-extra] [Profile] Allow profile merging with multiple correlate files. (PR #75957)

2024-01-18 Thread Zequan Wu via cfe-commits

https://github.com/ZequanWu updated 
https://github.com/llvm/llvm-project/pull/75957

>From d72f0e1ad7759bad81767418604d27f11d74d6de Mon Sep 17 00:00:00 2001
From: Zequan Wu 
Date: Tue, 19 Dec 2023 12:32:15 -0500
Subject: [PATCH 1/5] [Profile] Allow profile merging with multiple correlate
 files.

---
 .../Linux/instrprof-correlation-mixed.test|  33 
 .../Linux/instrprof-debug-info-correlate.c|  19 ++
 .../llvm/ProfileData/InstrProfCorrelator.h| 124 ++---
 .../llvm/ProfileData/InstrProfReader.h|  17 +-
 llvm/lib/Object/BuildID.cpp   |  18 ++
 llvm/lib/ProfileData/InstrProfCorrelator.cpp  | 164 +-
 llvm/lib/ProfileData/InstrProfReader.cpp  |  26 ++-
 llvm/tools/llvm-profdata/llvm-profdata.cpp|  84 +
 8 files changed, 358 insertions(+), 127 deletions(-)
 create mode 100644 
compiler-rt/test/profile/Linux/instrprof-correlation-mixed.test

diff --git a/compiler-rt/test/profile/Linux/instrprof-correlation-mixed.test 
b/compiler-rt/test/profile/Linux/instrprof-correlation-mixed.test
new file mode 100644
index 000..8cc4611eec4f0bb
--- /dev/null
+++ b/compiler-rt/test/profile/Linux/instrprof-correlation-mixed.test
@@ -0,0 +1,33 @@
+// REQUIRES: lld-available
+// Test llvm-profdata merging with multiple correlation files mixing different 
correlation modes.
+
+// RUN: %clang_pgogen -o %t.normal -mllvm --disable-vp=true 
%S/../Inputs/instrprof-debug-info-correlate-main.cpp 
%S/../Inputs/instrprof-debug-info-correlate-foo.cpp
+// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t.normal
+// RUN: llvm-profdata merge -o %t.normal.profdata %t.profraw
+
+// Compiling with differnt configs.
+// RUN: %clang_pgogen -o %t -mllvm --disable-vp=true 
%S/../Inputs/instrprof-debug-info-correlate-main.cpp -c -o %t-main.o
+// RUN: %clang_pgogen -o %t -g -mllvm --debug-info-correlate -mllvm 
--disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp -c -o 
%t-main.debug.o
+// RUN: %clang_pgogen -o %t -g -mllvm --debug-info-correlate -mllvm 
--disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-foo.cpp -fpic 
-shared -Wl,--build-id -o %t-libfoo.debug.so
+// RUN: %clang_pgogen -o %t -mllvm -profile-correlate=binary -mllvm 
--disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-foo.cpp -fpic 
-shared -Wl,--build-id -o %t-libfoo.binary.so
+
+// Test mixing default raw profile and lightweight raw profile generated with 
debug info correlate.
+// The raw profiles are mixed in %t.proflite.
+// RUN: %clang_pgogen -o %t %t-main.o %t-libfoo.debug.so -Wl,--build-id -o %t
+// RUN: env LLVM_PROFILE_FILE=%t.proflite %run %t
+// RUN: llvm-profdata merge -o %t.profdata --debug-info=%t-libfoo.debug.so 
%t.proflite
+// RUN: diff <(llvm-profdata show --all-functions --counts %t.normal.profdata) 
<(llvm-profdata show --all-functions --counts %t.profdata)
+// Two separate raw profiles.
+// RUN: rm -rf %t.dir && mkdir %t.dir
+// RUN: env LLVM_PROFILE_FILE=%t.dir/raw%m.proflite %run %t
+// RUN: llvm-profdata merge -o %t.profdata --debug-info=%t-libfoo.debug.so 
%t.dir
+// RUN: diff <(llvm-profdata show --all-functions --counts %t.normal.profdata) 
<(llvm-profdata show --all-functions --counts %t.profdata)
+
+// Test lightweight raw profiles generated with debug info correlate and 
binary correlate.
+// Note we can not mix different correlation modes in static linking because 
when merging, the same correlate file can not be used for more than one 
correaltion mode.
+// Two separate lightweight raw profiles.
+// RUN: %clang_pgogen -o %t -g %t-main.debug.o %t-libfoo.binary.so 
-Wl,--build-id -o %t
+// RUN: rm -rf %t.dir && mkdir %t.dir
+// RUN: env LLVM_PROFILE_FILE=%t.dir/raw%m.proflite %run %t
+// RUN: llvm-profdata merge -o %t.profdata --debug-info=%t 
--binary-file=%t-libfoo.binary.so %t.dir
+// RUN: diff <(llvm-profdata show --all-functions --counts %t.normal.profdata) 
<(llvm-profdata show --all-functions --counts %t.profdata)
diff --git a/compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c 
b/compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
index a918d7b6299005e..47dbf3c87e68f1d 100644
--- a/compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
+++ b/compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
@@ -25,6 +25,25 @@
 
 // RUN: diff <(llvm-profdata show --all-functions --counts 
%t.cov.normal.profdata) <(llvm-profdata show --all-functions --counts 
%t.cov.profdata)
 
+// Test debug info correlate with build id.
+
+// Both binaries are built with build id.
+// RUN: %clang_pgogen -o %t -g -mllvm --debug-info-correlate -mllvm 
--disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-foo.cpp -c -fpic 
-shared -Wl,--build-id -o %t-libfoo.so
+// RUN: %clang_pgogen -o %t -g -mllvm --debug-info-correlate -mllvm 
--disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp 
%t-libfoo.so -Wl,--build-id -o %t
+// RUN: env LLVM_PROFILE_FILE=%t.proflite %run %t
+// RUN: llvm-profdata 

[llvm] [libcxx] [compiler-rt] [clang] [mlir] [asan] Enable StackSafetyAnalysis by default (PR #77210)

2024-01-11 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

Reverted at e7f794875169811f3801fad6d40bb9fe833e1a69. Will file an issue to 
track it once reducing is done.

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


[libcxx] [clang] [llvm] [compiler-rt] [mlir] [asan] Enable StackSafetyAnalysis by default (PR #77210)

2024-01-11 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

Heads up! This causes clang crash:
cmd:
```
clang++ "-cc1" "-triple" "x86_64-apple-macosx10.15.0" 
"-Wundef-prefix=TARGET_OS_" "-Werror=undef-prefix" 
"-Wdeprecated-objc-isa-usage" "-Werror=deprecated-objc-isa-usage" "-emit-obj" 
"-femit-dwarf-unwind=no-compact-unwind" "-disable-free" 
"-clear-ast-before-backend" "-main-file-name" "glslang_lex_autogen.cpp" 
"-mrelocation-model" "pic" "-pic-level" "2" "-fmerge-all-constants" 
"-fno-delete-null-pointer-checks" "-mframe-pointer=all" "-relaxed-aliasing" 
"-ffp-contract=off" "-fno-rounding-math" "-funwind-tables=2" 
"-target-sdk-version=14.0" "-fcompatibility-qualified-id-block-type-checking" 
"-fvisibility-inlines-hidden-static-local-var" 
"-fbuiltin-headers-in-system-modules" "-target-cpu" "penryn" "-tune-cpu" 
"generic" "-debug-info-kind=line-tables-only" "-dwarf-version=4" 
"-debugger-tuning=lldb" 
"-fdebug-compilation-dir=/Volumes/Work/s/w/ir/cache/builder/src/out/Release" 
"-target-linker-version" "820.1" "-mllvm" 
"-crash-diagnostics-dir=../../tools/clang/crashreports" 
"-fcoverage-compilation-dir=/Volumes/Work/s/w/ir/cache/builder/src/out/Release" 
"-nostdinc++" "-D" "ANGLE_ENABLE_ESSL" "-D" "ANGLE_ENABLE_GLSL" "-D" 
"MEMORY_TOOL_REPLACES_ALLOCATOR" "-D" "ADDRESS_SANITIZER" "-D" 
"__STDC_CONSTANT_MACROS" "-D" "__STDC_FORMAT_MACROS" "-D" 
"_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE" "-D" 
"CR_XCODE_VERSION=1500" "-D" 
"CR_CLANG_REVISION=\"llvmorg-18-init-16856-gd1ecd12f-0\"" "-D" 
"_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS" "-D" 
"_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS" "-D" 
"CR_LIBCXX_REVISION=e4aac3ace5ad6e3737740daee3afeaa9c9ab0360" "-D" "NDEBUG" 
"-D" "NVALGRIND" "-D" "DYNAMIC_ANNOTATIONS_ENABLED=0" "-D" 
"ANGLE_OUTSIDE_WEBKIT" "-D" "ANGLE_DELEGATE_WORKERS=1" "-D" "ANGLE_USE_ABSEIL" 
"-D" "ABSL_ALLOCATOR_NOTHROW=1" "-D" "__DATE__=" "-D" "__TIME__=" "-D" 
"__TIMESTAMP__=" "-O2" "-Wall" "-Wextra" "-Wimplicit-fallthrough" 
"-Wextra-semi" "-Wunreachable-code-aggressive" "-Wthread-safety" 
"-Wunguarded-availability" "-Wno-missing-field-initializers" 
"-Wno-unused-parameter" "-Wno-psabi" "-Wloop-analysis" 
"-Wno-unneeded-internal-declaration" "-Wenum-compare-conditional" 
"-Wno-ignored-pragma-optimize" "-Wno-deprecated-builtins" 
"-Wno-bitfield-constant-conversion" "-Wno-deprecated-this-capture" 
"-Wno-invalid-offsetof" "-Wno-vla-extension" 
"-Wno-thread-safety-reference-return" "-Wshadow" "-Wno-builtin-macro-redefined" 
"-Wheader-hygiene" "-Wstring-conversion" "-Wtautological-overlap-compare" 
"-Wexit-time-destructors" "-Wglobal-constructors" "-Wbad-function-cast" 
"-Wconditional-uninitialized" "-Wextra-semi-stmt" "-Wfloat-conversion" 
"-Winconsistent-missing-destructor-override" "-Wmissing-field-initializers" 
"-Wnewline-eof" "-Wnon-virtual-dtor" "-Wredundant-parens" "-Wreturn-std-move" 
"-Wshadow" "-Wshadow-field" "-Wtautological-type-limit-compare" 
"-Wundefined-reinterpret-cast" "-Wunneeded-internal-declaration" 
"-Wunused-but-set-variable" "-Wsuggest-destructor-override" 
"-Wsuggest-override" "-Wparentheses" "-Wrange-loop-analysis" 
"-Wstrict-prototypes" "-Wunreachable-code-aggressive" "-Wshorten-64-to-32" 
"-Wno-c++11-narrowing-const-reference" "-Wno-trigraphs" "-std=c++20" 
"-fdeprecated-macro" "-ferror-limit" "19" "-fvisibility=hidden" 
"-fvisibility-inlines-hidden" "-fsanitize=address" 
"-fno-sanitize-memory-param-retval" "-fsanitize-address-use-after-scope" 
"-fsanitize-address-globals-dead-stripping" "-fno-assume-sane-operator-new" 
"-stack-protector" "1" "-fblocks" "-fencode-extended-block-signature" 
"-fno-rtti" "-fregister-global-dtors-with-atexit" "-fgnuc-version=4.2.1" 
"-fno-implicit-modules" "-fmax-type-align=16" "-Qn" "-fcolor-diagnostics" 
"-vectorize-loops" "-vectorize-slp" "-mllvm" "-instcombine-lower-dbg-declare=0" 
"-mllvm" "-split-threshold-for-reg-with-hint=0" "-fcomplete-member-pointers" 
"-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-x" "c++" "glslang_lex_autogen-7bfb0a.cpp"
```
Attached source code: 
[glslang_lex_autogen-7bfb0a.txt](https://github.com/llvm/llvm-project/files/13906543/glslang_lex_autogen-7bfb0a.txt)
 (Since it doesn't allow me to attach file ends with .cpp, I changed the suffix 
to .txt)


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


[clang] [Clang] Wide delimiters ('{{{') for expect strings (PR #77326)

2024-01-10 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

> @ZequanWu would either of these work for you?
> 
> ```c++
>  DCHECK_OK(foo); // 
> expected-error@components/reporting/util/status_macros.h:* 
> {{{CHECK,DCHECK,ASSERT,EXPECT}_OK do not accept a type other than Status or 
> StatusOr.}}}
> ```
> 
> or
> 
> ```c++
>  DCHECK_OK(foo); // 
> expected-error-re@components/reporting/util/status_macros.h:* 
> {{{CHECK,DCHECK,ASSERT,EXPECT}_OK do not accept a type other than Status or 
> StatusOr.}}
> ```

Thanks, it's a simple fix, just adding a space between 2nd and 3rd braces:
```
DCHECK_OK(foo);  // expected-error@components/reporting/util/status_macros.h:* 
{{ {CHECK,DCHECK,ASSERT,EXPECT}_OK do not accept a type other than Status or 
StatusOr.}}
```

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


[clang] [Clang] Wide delimiters ('{{{') for expect strings (PR #77326)

2024-01-10 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

Hi, this breaks our build. I don't know how to update the expectation to match

Current expectation:
  DCHECK_OK(foo);  // 
expected-error@components/reporting/util/status_macros.h:* 
{{{CHECK,DCHECK,ASSERT,EXPECT}_OK do not accept a type other than Status or 
StatusOr.}}



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


[clang-tools-extra] [llvm] [compiler-rt] [clang] [Profile] Allow profile merging with multiple correlate files. (PR #75957)

2024-01-10 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

Ping.


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


[compiler-rt] [clang] [llvm] [clang-tools-extra] [Profile] Allow profile merging with multiple correlate files. (PR #75957)

2024-01-02 Thread Zequan Wu via cfe-commits


@@ -118,18 +118,18 @@ cl::opt ProfiledBinary(
 "profiled-binary", cl::init(""),
 cl::desc("Path to binary from which the profile was collected."),
 cl::sub(ShowSubcommand), cl::sub(MergeSubcommand));
-cl::opt DebugInfoFilename(
-"debug-info", cl::init(""),
+cl::list DebugInfoFilenames(
+"debug-info",
 cl::desc(
 "For show, read and extract profile metadata from debug info and show "
 "the functions it found. For merge, use the provided debug info to "
 "correlate the raw profile."),
 cl::sub(ShowSubcommand), cl::sub(MergeSubcommand));
-cl::opt
-BinaryFilename("binary-file", cl::init(""),
-   cl::desc("For merge, use the provided unstripped bianry to "
-"correlate the raw profile."),
-   cl::sub(MergeSubcommand));
+cl::list
+BinaryFilenames("binary-file",
+cl::desc("For merge, use the provided unstripped bianry to 
"
+ "correlate the raw profile."),
+cl::sub(MergeSubcommand));

ZequanWu wrote:

> Another option would be to extend the pattern strings to support %b to expand 
> to the binary id or the binary name. Do you think that would work?

If the binary is built with binary id embedded, the raw profiles will also have 
binary id embedded. So there's no need to make `%b` expand to the binary id. 
The point for accepting multiple correlation files is to avoid some customizing 
scripts which associate raw profiles with different binaries. 

The output indexed profile file will contain profile information for multiple 
binaries. I'm not sure if this will cause problems/inconvenience for 
processing. What's your thoughts on this @gulfemsavrun @petrhosek?

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


[compiler-rt] [clang] [llvm] [clang-tools-extra] [Profile] Allow profile merging with multiple correlate files. (PR #75957)

2024-01-02 Thread Zequan Wu via cfe-commits


@@ -481,3 +509,49 @@ Error 
BinaryInstrProfCorrelator::correlateProfileNameImpl() {
   this->Names.append(this->Ctx->NameStart, this->Ctx->NameSize);
   return Error::success();
 }
+
+llvm::Expected> 
InstrProfCorrelators::get(
+ArrayRef>
+CorrelateInputs,
+uint32_t MaxWarnings) {
+  StringMap> CorrelatorMap;
+  StringMap FileMap;
+  auto WarnCounter =
+  std::make_unique(MaxWarnings);
+  std::unique_ptr CorrelateLock = std::make_unique();
+  std::unique_ptr WarnLock = std::make_unique();
+  for (const auto  : CorrelateInputs) {
+std::unique_ptr Correlator;
+if (auto Err = InstrProfCorrelator::get(Input.first, Input.second,
+*CorrelateLock.get(),
+*WarnLock.get(), WarnCounter.get())
+   .moveInto(Correlator))
+  return Err;
+std::string BuildID = toHex(Correlator->getBuildID());
+FileMap.try_emplace(BuildID, Input.first);
+bool Inserted =
+CorrelatorMap.try_emplace(BuildID, std::move(Correlator)).second;
+if (!Inserted && WarnCounter->shouldEmitWarning()) {
+  std::lock_guard Guard(*WarnLock);
+  WithColor::warning() << format(
+  "Duplicate build id (%s) found for %s and %s\n", BuildID.c_str(),
+  FileMap[BuildID].str().c_str(), Input.first.str().c_str());
+}
+  }
+  return std::make_unique(
+  std::move(CorrelatorMap), std::move(CorrelateLock), std::move(WarnLock),
+  std::move(WarnCounter));
+}
+
+llvm::Expected
+InstrProfCorrelators::getCorrelator(object::BuildIDRef BuildID) const {
+  std::string BuildIDStr = toHex(BuildID);
+  auto I = CorrelatorMap.find(BuildIDStr);
+  if (I == CorrelatorMap.end())
+return make_error(
+instrprof_error::unable_to_correlate_profile,
+"missing correlator file with build id " + BuildIDStr + "\n");
+  if (auto Err = I->getValue()->correlateProfileData())

ZequanWu wrote:

Right now, the parsing of correlation files is done before the parallelization 
starts. For each raw profiles, it parallelly associate parsed correlation info 
with lightweight raw profiles (which basically returns pointers to constant 
data and constant names)

> I guess we would still need an atomic counter to make sure we don't emit too 
> many warnings.

The warnings are only emitted at the time when parsing the correlation files 
which is before the parallelization starts. So, at least for now, we don't need 
atomic counter. If we want to parallelly parse correlation files, then we need 
lock or atomic counter to handle warning emissions.

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


[llvm] [compiler-rt] [clang] [clang-tools-extra] [Profile] Allow profile merging with multiple correlate files. (PR #75957)

2023-12-20 Thread Zequan Wu via cfe-commits


@@ -481,3 +509,49 @@ Error 
BinaryInstrProfCorrelator::correlateProfileNameImpl() {
   this->Names.append(this->Ctx->NameStart, this->Ctx->NameSize);
   return Error::success();
 }
+
+llvm::Expected> 
InstrProfCorrelators::get(
+ArrayRef>
+CorrelateInputs,
+uint32_t MaxWarnings) {
+  StringMap> CorrelatorMap;
+  StringMap FileMap;
+  auto WarnCounter =
+  std::make_unique(MaxWarnings);
+  std::unique_ptr CorrelateLock = std::make_unique();
+  std::unique_ptr WarnLock = std::make_unique();
+  for (const auto  : CorrelateInputs) {
+std::unique_ptr Correlator;
+if (auto Err = InstrProfCorrelator::get(Input.first, Input.second,
+*CorrelateLock.get(),
+*WarnLock.get(), WarnCounter.get())
+   .moveInto(Correlator))
+  return Err;
+std::string BuildID = toHex(Correlator->getBuildID());
+FileMap.try_emplace(BuildID, Input.first);
+bool Inserted =
+CorrelatorMap.try_emplace(BuildID, std::move(Correlator)).second;
+if (!Inserted && WarnCounter->shouldEmitWarning()) {
+  std::lock_guard Guard(*WarnLock);
+  WithColor::warning() << format(
+  "Duplicate build id (%s) found for %s and %s\n", BuildID.c_str(),
+  FileMap[BuildID].str().c_str(), Input.first.str().c_str());
+}
+  }
+  return std::make_unique(
+  std::move(CorrelatorMap), std::move(CorrelateLock), std::move(WarnLock),
+  std::move(WarnCounter));
+}
+
+llvm::Expected
+InstrProfCorrelators::getCorrelator(object::BuildIDRef BuildID) const {
+  std::string BuildIDStr = toHex(BuildID);
+  auto I = CorrelatorMap.find(BuildIDStr);
+  if (I == CorrelatorMap.end())
+return make_error(
+instrprof_error::unable_to_correlate_profile,
+"missing correlator file with build id " + BuildIDStr + "\n");
+  if (auto Err = I->getValue()->correlateProfileData())

ZequanWu wrote:

Part of the reason for doing "lazy correlation" is to allow parsing multiple 
correlate files parallelly, because when merging, llvm-profdata will parallelly 
read raw profiles. But I just noticed that there's mistake in the 
implementation (all Correlators share the same CorrelateLock so only one can 
correlate at a time) and we can do it in llvm-profdata.cpp later probably.

Removed mutex and atomics and call `correlateProfileData()` upfront when 
creating `InstrProfCorrelators`

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


[clang] [llvm] [compiler-rt] [clang-tools-extra] [Profile] Allow profile merging with multiple correlate files. (PR #75957)

2023-12-20 Thread Zequan Wu via cfe-commits


@@ -118,18 +118,18 @@ cl::opt ProfiledBinary(
 "profiled-binary", cl::init(""),
 cl::desc("Path to binary from which the profile was collected."),
 cl::sub(ShowSubcommand), cl::sub(MergeSubcommand));
-cl::opt DebugInfoFilename(
-"debug-info", cl::init(""),
+cl::list DebugInfoFilenames(
+"debug-info",
 cl::desc(
 "For show, read and extract profile metadata from debug info and show "
 "the functions it found. For merge, use the provided debug info to "
 "correlate the raw profile."),
 cl::sub(ShowSubcommand), cl::sub(MergeSubcommand));
-cl::opt
-BinaryFilename("binary-file", cl::init(""),
-   cl::desc("For merge, use the provided unstripped bianry to "
-"correlate the raw profile."),
-   cl::sub(MergeSubcommand));
+cl::list
+BinaryFilenames("binary-file",
+cl::desc("For merge, use the provided unstripped bianry to 
"
+ "correlate the raw profile."),
+cl::sub(MergeSubcommand));

ZequanWu wrote:

> It looks like we are switching from passing a single correlation file to a 
> list of correlation files. Is that so that we can pass all raw profiles into 
> a single llvm-profdata merge command?

Yes, that's the purpose. 

> Presumably we should know which binaries produce which raw profiles.

This isn't always the case. When there are shared libraries producing raw 
profiles and `LLVM_PROFILE_FILE=default-%4m.profraw`, we will get bunch of 
`default-{hash}.profraw` produced by all shared libraries and main executable. 
There's no way to differentiate which raw profiles are generated by which 
binaries. @gulfemsavrun also has use case for this situation: 
https://discourse.llvm.org/t/rfc-add-binary-profile-correlation-to-not-load-profile-metadata-sections-into-memory-at-runtime/74565/8?u=zequanwu

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


[compiler-rt] [llvm] [clang] [clang-tools-extra] [Profile] Allow profile merging with multiple correlate files. (PR #75957)

2023-12-20 Thread Zequan Wu via cfe-commits


@@ -25,6 +25,25 @@
 
 // RUN: diff <(llvm-profdata show --all-functions --counts 
%t.cov.normal.profdata) <(llvm-profdata show --all-functions --counts 
%t.cov.profdata)
 
+// Test debug info correlate with build id.

ZequanWu wrote:

The added test in `Linux/instrprof-debug-info-correlate.c` requires build id in 
the binaries. Does ld64 or ld64.lld have a flag to emit build id in binaries? I 
don't find such flag.

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


[compiler-rt] [clang] [clang-tools-extra] [llvm] [Profile] Allow profile merging with multiple correlate files. (PR #75957)

2023-12-20 Thread Zequan Wu via cfe-commits


@@ -0,0 +1,33 @@
+// REQUIRES: lld-available

ZequanWu wrote:

The added test in `Linux/instrprof-debug-info-correlate.c` requires build id. 
Does darwin linker ld64 or ld64.lld have the option to emit build id into 
binary? I don't find such flag.

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


[compiler-rt] [llvm] [clang] [clang-tools-extra] [Profile] Allow profile merging with multiple correlate files. (PR #75957)

2023-12-20 Thread Zequan Wu via cfe-commits


@@ -0,0 +1,33 @@
+// REQUIRES: lld-available

ZequanWu wrote:

Added by mistake. Removed.

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


[llvm] [compiler-rt] [clang] [clang-tools-extra] [Profile] Allow profile merging with multiple correlate files. (PR #75957)

2023-12-20 Thread Zequan Wu via cfe-commits

https://github.com/ZequanWu updated 
https://github.com/llvm/llvm-project/pull/75957

>From d72f0e1ad7759bad81767418604d27f11d74d6de Mon Sep 17 00:00:00 2001
From: Zequan Wu 
Date: Tue, 19 Dec 2023 12:32:15 -0500
Subject: [PATCH 1/4] [Profile] Allow profile merging with multiple correlate
 files.

---
 .../Linux/instrprof-correlation-mixed.test|  33 
 .../Linux/instrprof-debug-info-correlate.c|  19 ++
 .../llvm/ProfileData/InstrProfCorrelator.h| 124 ++---
 .../llvm/ProfileData/InstrProfReader.h|  17 +-
 llvm/lib/Object/BuildID.cpp   |  18 ++
 llvm/lib/ProfileData/InstrProfCorrelator.cpp  | 164 +-
 llvm/lib/ProfileData/InstrProfReader.cpp  |  26 ++-
 llvm/tools/llvm-profdata/llvm-profdata.cpp|  84 +
 8 files changed, 358 insertions(+), 127 deletions(-)
 create mode 100644 
compiler-rt/test/profile/Linux/instrprof-correlation-mixed.test

diff --git a/compiler-rt/test/profile/Linux/instrprof-correlation-mixed.test 
b/compiler-rt/test/profile/Linux/instrprof-correlation-mixed.test
new file mode 100644
index 00..8cc4611eec4f0b
--- /dev/null
+++ b/compiler-rt/test/profile/Linux/instrprof-correlation-mixed.test
@@ -0,0 +1,33 @@
+// REQUIRES: lld-available
+// Test llvm-profdata merging with multiple correlation files mixing different 
correlation modes.
+
+// RUN: %clang_pgogen -o %t.normal -mllvm --disable-vp=true 
%S/../Inputs/instrprof-debug-info-correlate-main.cpp 
%S/../Inputs/instrprof-debug-info-correlate-foo.cpp
+// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t.normal
+// RUN: llvm-profdata merge -o %t.normal.profdata %t.profraw
+
+// Compiling with differnt configs.
+// RUN: %clang_pgogen -o %t -mllvm --disable-vp=true 
%S/../Inputs/instrprof-debug-info-correlate-main.cpp -c -o %t-main.o
+// RUN: %clang_pgogen -o %t -g -mllvm --debug-info-correlate -mllvm 
--disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp -c -o 
%t-main.debug.o
+// RUN: %clang_pgogen -o %t -g -mllvm --debug-info-correlate -mllvm 
--disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-foo.cpp -fpic 
-shared -Wl,--build-id -o %t-libfoo.debug.so
+// RUN: %clang_pgogen -o %t -mllvm -profile-correlate=binary -mllvm 
--disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-foo.cpp -fpic 
-shared -Wl,--build-id -o %t-libfoo.binary.so
+
+// Test mixing default raw profile and lightweight raw profile generated with 
debug info correlate.
+// The raw profiles are mixed in %t.proflite.
+// RUN: %clang_pgogen -o %t %t-main.o %t-libfoo.debug.so -Wl,--build-id -o %t
+// RUN: env LLVM_PROFILE_FILE=%t.proflite %run %t
+// RUN: llvm-profdata merge -o %t.profdata --debug-info=%t-libfoo.debug.so 
%t.proflite
+// RUN: diff <(llvm-profdata show --all-functions --counts %t.normal.profdata) 
<(llvm-profdata show --all-functions --counts %t.profdata)
+// Two separate raw profiles.
+// RUN: rm -rf %t.dir && mkdir %t.dir
+// RUN: env LLVM_PROFILE_FILE=%t.dir/raw%m.proflite %run %t
+// RUN: llvm-profdata merge -o %t.profdata --debug-info=%t-libfoo.debug.so 
%t.dir
+// RUN: diff <(llvm-profdata show --all-functions --counts %t.normal.profdata) 
<(llvm-profdata show --all-functions --counts %t.profdata)
+
+// Test lightweight raw profiles generated with debug info correlate and 
binary correlate.
+// Note we can not mix different correlation modes in static linking because 
when merging, the same correlate file can not be used for more than one 
correaltion mode.
+// Two separate lightweight raw profiles.
+// RUN: %clang_pgogen -o %t -g %t-main.debug.o %t-libfoo.binary.so 
-Wl,--build-id -o %t
+// RUN: rm -rf %t.dir && mkdir %t.dir
+// RUN: env LLVM_PROFILE_FILE=%t.dir/raw%m.proflite %run %t
+// RUN: llvm-profdata merge -o %t.profdata --debug-info=%t 
--binary-file=%t-libfoo.binary.so %t.dir
+// RUN: diff <(llvm-profdata show --all-functions --counts %t.normal.profdata) 
<(llvm-profdata show --all-functions --counts %t.profdata)
diff --git a/compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c 
b/compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
index a918d7b6299005..47dbf3c87e68f1 100644
--- a/compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
+++ b/compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
@@ -25,6 +25,25 @@
 
 // RUN: diff <(llvm-profdata show --all-functions --counts 
%t.cov.normal.profdata) <(llvm-profdata show --all-functions --counts 
%t.cov.profdata)
 
+// Test debug info correlate with build id.
+
+// Both binaries are built with build id.
+// RUN: %clang_pgogen -o %t -g -mllvm --debug-info-correlate -mllvm 
--disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-foo.cpp -c -fpic 
-shared -Wl,--build-id -o %t-libfoo.so
+// RUN: %clang_pgogen -o %t -g -mllvm --debug-info-correlate -mllvm 
--disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp 
%t-libfoo.so -Wl,--build-id -o %t
+// RUN: env LLVM_PROFILE_FILE=%t.proflite %run %t
+// RUN: llvm-profdata 

[clang] [llvm] [compiler-rt] [clang-tools-extra] [Profile] Allow profile merging with multiple correlate files. (PR #75957)

2023-12-20 Thread Zequan Wu via cfe-commits

https://github.com/ZequanWu updated 
https://github.com/llvm/llvm-project/pull/75957

>From d72f0e1ad7759bad81767418604d27f11d74d6de Mon Sep 17 00:00:00 2001
From: Zequan Wu 
Date: Tue, 19 Dec 2023 12:32:15 -0500
Subject: [PATCH 1/3] [Profile] Allow profile merging with multiple correlate
 files.

---
 .../Linux/instrprof-correlation-mixed.test|  33 
 .../Linux/instrprof-debug-info-correlate.c|  19 ++
 .../llvm/ProfileData/InstrProfCorrelator.h| 124 ++---
 .../llvm/ProfileData/InstrProfReader.h|  17 +-
 llvm/lib/Object/BuildID.cpp   |  18 ++
 llvm/lib/ProfileData/InstrProfCorrelator.cpp  | 164 +-
 llvm/lib/ProfileData/InstrProfReader.cpp  |  26 ++-
 llvm/tools/llvm-profdata/llvm-profdata.cpp|  84 +
 8 files changed, 358 insertions(+), 127 deletions(-)
 create mode 100644 
compiler-rt/test/profile/Linux/instrprof-correlation-mixed.test

diff --git a/compiler-rt/test/profile/Linux/instrprof-correlation-mixed.test 
b/compiler-rt/test/profile/Linux/instrprof-correlation-mixed.test
new file mode 100644
index 00..8cc4611eec4f0b
--- /dev/null
+++ b/compiler-rt/test/profile/Linux/instrprof-correlation-mixed.test
@@ -0,0 +1,33 @@
+// REQUIRES: lld-available
+// Test llvm-profdata merging with multiple correlation files mixing different 
correlation modes.
+
+// RUN: %clang_pgogen -o %t.normal -mllvm --disable-vp=true 
%S/../Inputs/instrprof-debug-info-correlate-main.cpp 
%S/../Inputs/instrprof-debug-info-correlate-foo.cpp
+// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t.normal
+// RUN: llvm-profdata merge -o %t.normal.profdata %t.profraw
+
+// Compiling with differnt configs.
+// RUN: %clang_pgogen -o %t -mllvm --disable-vp=true 
%S/../Inputs/instrprof-debug-info-correlate-main.cpp -c -o %t-main.o
+// RUN: %clang_pgogen -o %t -g -mllvm --debug-info-correlate -mllvm 
--disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp -c -o 
%t-main.debug.o
+// RUN: %clang_pgogen -o %t -g -mllvm --debug-info-correlate -mllvm 
--disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-foo.cpp -fpic 
-shared -Wl,--build-id -o %t-libfoo.debug.so
+// RUN: %clang_pgogen -o %t -mllvm -profile-correlate=binary -mllvm 
--disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-foo.cpp -fpic 
-shared -Wl,--build-id -o %t-libfoo.binary.so
+
+// Test mixing default raw profile and lightweight raw profile generated with 
debug info correlate.
+// The raw profiles are mixed in %t.proflite.
+// RUN: %clang_pgogen -o %t %t-main.o %t-libfoo.debug.so -Wl,--build-id -o %t
+// RUN: env LLVM_PROFILE_FILE=%t.proflite %run %t
+// RUN: llvm-profdata merge -o %t.profdata --debug-info=%t-libfoo.debug.so 
%t.proflite
+// RUN: diff <(llvm-profdata show --all-functions --counts %t.normal.profdata) 
<(llvm-profdata show --all-functions --counts %t.profdata)
+// Two separate raw profiles.
+// RUN: rm -rf %t.dir && mkdir %t.dir
+// RUN: env LLVM_PROFILE_FILE=%t.dir/raw%m.proflite %run %t
+// RUN: llvm-profdata merge -o %t.profdata --debug-info=%t-libfoo.debug.so 
%t.dir
+// RUN: diff <(llvm-profdata show --all-functions --counts %t.normal.profdata) 
<(llvm-profdata show --all-functions --counts %t.profdata)
+
+// Test lightweight raw profiles generated with debug info correlate and 
binary correlate.
+// Note we can not mix different correlation modes in static linking because 
when merging, the same correlate file can not be used for more than one 
correaltion mode.
+// Two separate lightweight raw profiles.
+// RUN: %clang_pgogen -o %t -g %t-main.debug.o %t-libfoo.binary.so 
-Wl,--build-id -o %t
+// RUN: rm -rf %t.dir && mkdir %t.dir
+// RUN: env LLVM_PROFILE_FILE=%t.dir/raw%m.proflite %run %t
+// RUN: llvm-profdata merge -o %t.profdata --debug-info=%t 
--binary-file=%t-libfoo.binary.so %t.dir
+// RUN: diff <(llvm-profdata show --all-functions --counts %t.normal.profdata) 
<(llvm-profdata show --all-functions --counts %t.profdata)
diff --git a/compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c 
b/compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
index a918d7b6299005..47dbf3c87e68f1 100644
--- a/compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
+++ b/compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c
@@ -25,6 +25,25 @@
 
 // RUN: diff <(llvm-profdata show --all-functions --counts 
%t.cov.normal.profdata) <(llvm-profdata show --all-functions --counts 
%t.cov.profdata)
 
+// Test debug info correlate with build id.
+
+// Both binaries are built with build id.
+// RUN: %clang_pgogen -o %t -g -mllvm --debug-info-correlate -mllvm 
--disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-foo.cpp -c -fpic 
-shared -Wl,--build-id -o %t-libfoo.so
+// RUN: %clang_pgogen -o %t -g -mllvm --debug-info-correlate -mllvm 
--disable-vp=true %S/../Inputs/instrprof-debug-info-correlate-main.cpp 
%t-libfoo.so -Wl,--build-id -o %t
+// RUN: env LLVM_PROFILE_FILE=%t.proflite %run %t
+// RUN: llvm-profdata 

[compiler-rt] [clang] [llvm] [InstrProf] Single byte counters in coverage (PR #75425)

2023-12-15 Thread Zequan Wu via cfe-commits


@@ -234,8 +246,20 @@ struct MapRegionCounters : public 
RecursiveASTVisitor {
 if (Hash.getHashVersion() == PGO_HASH_V1)
   return Base::TraverseIfStmt(If);
 
+// When single byte coverage mode is enabled, add a counter to then and
+// else.
+for (Stmt *CS : If->children()) {
+  if (!CS || !llvm::EnableSingleByteCoverage)

ZequanWu wrote:

Maybe hoist `llvm::EnableSingleByteCoverage` outside the loop as this is not 
going to change. Same for the following.

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


[clang] [compiler-rt] [llvm] [InstrProf] Single byte counters in coverage (PR #75425)

2023-12-15 Thread Zequan Wu via cfe-commits


@@ -569,16 +577,26 @@ struct CounterCoverageMappingBuilder
 
   /// Return a counter for the subtraction of \c RHS from \c LHS
   Counter subtractCounters(Counter LHS, Counter RHS, bool Simplify = true) {
+if (llvm::EnableSingleByteCoverage)
+  assert(
+  0 &&
+  "cannot subtract counters when single byte coverage mode is 
enabled");

ZequanWu wrote:

This can be simplifies to `assert(!llvm::EnableSingleByteCoverage && "cannot 
subtract counters when single byte coverage mode is enabled")`. Same for the 
following asserts.

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


[clang-tools-extra] [compiler-rt] [clang] [llvm] [flang] [lldb] [mlir] [Profile] Add binary profile correlation for code coverage. (PR #69493)

2023-12-14 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

> Well, seems like someone broke ToT w/ a compiler error. I'll let you know if 
> the forward fix fails to address the issue.

The latest build passed: 
https://luci-milo.appspot.com/ui/p/fuchsia/builders/toolchain.ci/clang-linux-x64/b8761696377585255057/overview.

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


[llvm] [mlir] [lldb] [clang-tools-extra] [compiler-rt] [clang] [flang] [Profile] Add binary profile correlation for code coverage. (PR #69493)

2023-12-14 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

> Seems like a mismatch on the diff, so maybe the check is too stringent.
> 
> If this will take a while to fix, would you mind reverting until it can be 
> addressed?

It passed for me locally on x64. Maybe I should use `diff <(llvm-profdata show 
--all-functions --counts %t.normal.profdata) <(llvm-profdata show 
--all-functions --counts %t.d4.profdata)` like it does on debug-info correlate 
test:
https://github.com/llvm/llvm-project/blob/29e043cb5c2efaad7fb203fb8240a91b77ca0c5b/compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c#L10

Sent a possible fix at: 
https://github.com/llvm/llvm-project/commit/f34325307eb36d6032ccea3773e3e0c1746b7f98,
 hope that fixes it.



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


[clang] [llvm] [mlir] [lldb] [clang-tools-extra] [compiler-rt] [flang] [Profile] Add binary profile correlation for code coverage. (PR #69493)

2023-12-14 Thread Zequan Wu via cfe-commits

https://github.com/ZequanWu closed 
https://github.com/llvm/llvm-project/pull/69493
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [flang] [llvm] [lldb] [mlir] [clang-tools-extra] [Profile] Add binary profile correlation for code coverage. (PR #69493)

2023-12-12 Thread Zequan Wu via cfe-commits


@@ -0,0 +1,9 @@
+// RUN: %clang_cc1  -fprofile-instrument=clang -fcoverage-mapping -emit-llvm 
-o - %s | FileCheck %s
+// RUN: %clang_cc1 -mllvm -profile-correlate=binary -fprofile-instrument=clang 
-fcoverage-mapping -emit-llvm -o - %s | FileCheck %s 
--check-prefix=BIN-CORRELATE
+
+// CHECK: @__llvm_profile_raw_version = {{.*}} i64 9

ZequanWu wrote:

ditto

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


[llvm] [compiler-rt] [lldb] [clang] [mlir] [flang] [clang-tools-extra] [Profile] Add binary profile correlation for code coverage. (PR #69493)

2023-12-12 Thread Zequan Wu via cfe-commits


@@ -1829,6 +1833,22 @@ void CoverageMappingModuleGen::emit() {
  llvm::GlobalValue::InternalLinkage, NamesArrVal,
  llvm::getCoverageUnusedNamesVarName());
   }
+  const StringRef VarName(INSTR_PROF_QUOTE(INSTR_PROF_RAW_VERSION_VAR));

ZequanWu wrote:

I already reverted changes in Clang because `VARIANT_MASK_BIN_CORRELATE` flag 
is no longer necessary: 
https://github.com/llvm/llvm-project/pull/69493#issuecomment-1815324995

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


[clang] [llvm] [lldb] [mlir] [compiler-rt] [clang-tools-extra] [flang] [Profile] Add binary profile correlation for code coverage. (PR #69493)

2023-12-12 Thread Zequan Wu via cfe-commits


@@ -1829,6 +1833,22 @@ void CoverageMappingModuleGen::emit() {
  llvm::GlobalValue::InternalLinkage, NamesArrVal,
  llvm::getCoverageUnusedNamesVarName());
   }
+  const StringRef VarName(INSTR_PROF_QUOTE(INSTR_PROF_RAW_VERSION_VAR));
+  llvm::Type *IntTy64 = llvm::Type::getInt64Ty(Ctx);
+  uint64_t ProfileVersion = INSTR_PROF_RAW_VERSION;
+  if (llvm::ProfileCorrelate == llvm::InstrProfCorrelator::BINARY)
+ProfileVersion |= VARIANT_MASK_BIN_CORRELATE;

ZequanWu wrote:

ditto

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


[clang] [flang] [llvm] [clang-tools-extra] [mlir] [lldb] [compiler-rt] [Profile] Add binary profile correlation for code coverage. (PR #69493)

2023-12-05 Thread Zequan Wu via cfe-commits


@@ -702,6 +708,8 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
 #define INSTR_PROF_COVMAP_COMMON __llvm_covmap
 #define INSTR_PROF_COVFUN_COMMON __llvm_covfun
 #define INSTR_PROF_ORDERFILE_COMMON __llvm_orderfile

ZequanWu wrote:

Done.

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


[mlir] [llvm] [lldb] [flang] [clang] [compiler-rt] [clang-tools-extra] [Profile] Add binary profile correlation for code coverage. (PR #69493)

2023-12-05 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

> Can you break up all the changes to tests that replace 
> `-debug-info-correlate` with `--profile-correlate=debug-info` into a separate 
> PR to reduce the size of this PR?

Done.

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


[llvm] [mlir] [clang-tools-extra] [clang] [lldb] [compiler-rt] [flang] [Profile] Add binary profile correlation for code coverage. (PR #69493)

2023-11-28 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

Ping.

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


[llvm] [clang-tools-extra] [lldb] [compiler-rt] [flang] [clang] [mlir] [Profile] Add binary profile correlation for code coverage. (PR #69493)

2023-11-16 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

> Some further discussion/pre-work needed before proceeding with this PR.

These two discussions are addressed and this is ready to be reviewed.

1. Support for merging with multiple correlation files will be done in a 
separate change.
2. Removed the `VARIANT_MASK_BIN_CORRELATE` and runtime check for it to 
determine if name/data sections should be skipped. Instead, new section names 
are used (`__llvm_covdata` and `__llvm_covnames`).

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


[clang] Supports viewing class member variables in lambda when using the vs debugger (PR #71564)

2023-11-16 Thread Zequan Wu via cfe-commits

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


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


[clang] Supports viewing class member variables in lambda when using the vs debugger (PR #71564)

2023-11-16 Thread Zequan Wu via cfe-commits


@@ -0,0 +1,48 @@
+// RUN: %clang_cl --target=x86_64-windows-msvc /c /Z7 -o %t.obj -- %s

ZequanWu wrote:

I think you are missing `-gcodeview` in the command line to emit the debug 
info. The change should reflect on a metadata. `llvm/test/DebugInfo/COFF` is 
the place to test the phase when IR being lowered to object file.  
`clang/test/CodeGenCXX` is for testing C++ code to IR.

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


[llvm] [compiler-rt] [clang-tools-extra] [lldb] [clang] [flang] [mlir] [Profile] Add binary profile correlation for code coverage. (PR #69493)

2023-11-15 Thread Zequan Wu via cfe-commits

https://github.com/ZequanWu edited 
https://github.com/llvm/llvm-project/pull/69493
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[flang] [compiler-rt] [mlir] [llvm] [clang] [clang-tools-extra] [lldb] [Profile] Add binary profile correlation for code coverage. (PR #69493)

2023-11-15 Thread Zequan Wu via cfe-commits

https://github.com/ZequanWu edited 
https://github.com/llvm/llvm-project/pull/69493
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [mlir] [clang] [lldb] [compiler-rt] [llvm] [flang] [Profile] Add binary profile correlation for code coverage. (PR #69493)

2023-11-15 Thread Zequan Wu via cfe-commits

https://github.com/ZequanWu edited 
https://github.com/llvm/llvm-project/pull/69493
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [mlir] [clang] [lldb] [compiler-rt] [llvm] [flang] [Profile] Add binary profile correlation to offload profile metadata at runtime. (PR #69493)

2023-11-15 Thread Zequan Wu via cfe-commits


@@ -0,0 +1,46 @@
+// REQUIRES: linux || windows
+// Default
+// RUN: %clang -o %t.normal -fprofile-instr-generate -fcoverage-mapping 
-fuse-ld=lld %S/Inputs/instrprof-debug-info-correlate-main.cpp 
%S/Inputs/instrprof-debug-info-correlate-foo.cpp
+// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t.normal
+// RUN: llvm-profdata merge -o %t.normal.profdata %t.profraw
+// RUN: llvm-cov report --instr-profile=%t.normal.profdata %t.normal > 
%t.normal.report
+// RUN: llvm-cov show --instr-profile=%t.normal.profdata %t.normal > 
%t.normal.show
+
+// With -profile-correlate=binary flag
+// RUN: %clang -o %t-1.exe -fprofile-instr-generate -fcoverage-mapping -mllvm 
-profile-correlate=binary -fuse-ld=lld 
%S/Inputs/instrprof-debug-info-correlate-main.cpp 
%S/Inputs/instrprof-debug-info-correlate-foo.cpp

ZequanWu wrote:

On Windows, it expands to `.tmp.exe`.

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


[compiler-rt] [flang] [llvm] [lldb] [clang-tools-extra] [clang] [mlir] [Profile] Add binary profile correlation to offload profile metadata at runtime. (PR #69493)

2023-11-15 Thread Zequan Wu via cfe-commits


@@ -195,8 +195,14 @@ OPTIONS
 .. option:: --debug-info=
 
  Specify the executable or ``.dSYM`` that contains debug info for the raw 
profile.
- When ``-debug-info-correlate`` was used for instrumentation, use this option
- to correlate the raw profile.
+ When ``-profile-correlate=debug-info`` was used for instrumentation, use this

ZequanWu wrote:

Done.

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


[lldb] [clang-tools-extra] [clang] [mlir] [flang] [llvm] [compiler-rt] [Profile] Add binary profile correlation to offload profile metadata at runtime. (PR #69493)

2023-11-15 Thread Zequan Wu via cfe-commits


@@ -1341,20 +1344,26 @@ void 
InstrProfiling::createDataVariable(InstrProfCntrInstBase *Inc,
   }
   auto *Data =
   new GlobalVariable(*M, DataTy, false, Linkage, nullptr, DataVarName);
-  // Reference the counter variable with a label difference (link-time
-  // constant).
-  auto *RelativeCounterPtr =
-  ConstantExpr::getSub(ConstantExpr::getPtrToInt(CounterPtr, IntPtrTy),
-   ConstantExpr::getPtrToInt(Data, IntPtrTy));
-
-  // Bitmaps are relative to the same data variable as profile counters.
+  Constant *RelativeCounterPtr;
   GlobalVariable *BitmapPtr = PD.RegionBitmaps;
   Constant *RelativeBitmapPtr = ConstantInt::get(IntPtrTy, 0);
-
-  if (BitmapPtr != nullptr) {
-RelativeBitmapPtr =
-ConstantExpr::getSub(ConstantExpr::getPtrToInt(BitmapPtr, IntPtrTy),
+  // By default counter ptr and bitmap ptr are address relative to data 
section.

ZequanWu wrote:

Done.

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


[compiler-rt] [flang] [mlir] [llvm] [clang] [clang-tools-extra] [lldb] [Profile] Add binary profile correlation to offload profile metadata at runtime. (PR #69493)

2023-11-15 Thread Zequan Wu via cfe-commits


@@ -1331,6 +1336,18 @@ static int merge_main(int argc, const char *argv[]) {
"(default: 1)"));
 
   cl::ParseCommandLineOptions(argc, argv, "LLVM profile data merger\n");
+  if (!DebugInfoFilename.empty() && !BinaryFilename.empty()) {
+exitWithError("Expected only one of -debug-info, -binary-file");

ZequanWu wrote:

Done.

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


[flang] [compiler-rt] [lldb] [llvm] [mlir] [clang] [clang-tools-extra] [Profile] Add binary profile correlation to offload profile metadata at runtime. (PR #69493)

2023-11-15 Thread Zequan Wu via cfe-commits


@@ -1331,6 +1336,18 @@ static int merge_main(int argc, const char *argv[]) {
"(default: 1)"));
 
   cl::ParseCommandLineOptions(argc, argv, "LLVM profile data merger\n");
+  if (!DebugInfoFilename.empty() && !BinaryFilename.empty()) {
+exitWithError("Expected only one of -debug-info, -binary-file");
+  }
+  std::string CorrelateFilename = "";

ZequanWu wrote:

Done.

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


[clang] [flang] [llvm] [clang-tools-extra] [lldb] [compiler-rt] [mlir] [Profile] Add binary profile correlation to offload profile metadata at runtime. (PR #69493)

2023-11-15 Thread Zequan Wu via cfe-commits

https://github.com/ZequanWu commented:

>  "binary" is ambiguous. I wonder whether object file correlation is better. 
> llvm-symbolizer has an option --obj=xxx.
llvm-symbolizer's `--obj` could take an pre-linking object file. But here we 
need to take post-linked binary for merging.

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


[lldb] [mlir] [llvm] [clang] [compiler-rt] [flang] [clang-tools-extra] [Profile] Add binary profile correlation to offload profile metadata at runtime. (PR #69493)

2023-11-15 Thread Zequan Wu via cfe-commits


@@ -46,14 +73,38 @@ const char *InstrProfCorrelator::NumCountersAttributeName = 
"Num Counters";
 
 llvm::Expected>
 InstrProfCorrelator::Context::get(std::unique_ptr Buffer,
-  const object::ObjectFile ) {
+  const object::ObjectFile ,
+  ProfCorrelatorKind FileKind) {
+  auto C = std::make_unique();
   auto CountersSection = getInstrProfSection(Obj, IPSK_cnts);
   if (auto Err = CountersSection.takeError())
 return std::move(Err);
-  auto C = std::make_unique();
+  if (FileKind == InstrProfCorrelator::BINARY) {
+auto DataSection = getInstrProfSection(Obj, IPSK_data);
+if (auto Err = DataSection.takeError())
+  return std::move(Err);
+auto DataOrErr = DataSection->getContents();
+if (!DataOrErr)
+  return DataOrErr.takeError();
+auto NameSection = getInstrProfSection(Obj, IPSK_name);
+if (auto Err = NameSection.takeError())
+  return std::move(Err);
+auto NameOrErr = NameSection->getContents();
+if (!NameOrErr)
+  return NameOrErr.takeError();
+C->DataStart = DataOrErr->data();
+C->DataEnd = DataOrErr->data() + DataOrErr->size();
+C->NameStart = NameOrErr->data();
+C->NameSize = NameOrErr->size();
+  }
   C->Buffer = std::move(Buffer);
   C->CountersSectionStart = CountersSection->getAddress();
   C->CountersSectionEnd = C->CountersSectionStart + CountersSection->getSize();
+  // In COFF object file, there's a null byte at the beginning of the counter
+  // section which doesn't exist in raw profile.
+  if (Obj.getTripleObjectFormat() == Triple::COFF)
+C->CountersSectionStart++;

ZequanWu wrote:

Done.

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


[flang] [lldb] [compiler-rt] [llvm] [clang-tools-extra] [clang] [mlir] [Profile] Add binary profile correlation to offload profile metadata at runtime. (PR #69493)

2023-11-15 Thread Zequan Wu via cfe-commits


@@ -1829,6 +1833,22 @@ void CoverageMappingModuleGen::emit() {
  llvm::GlobalValue::InternalLinkage, NamesArrVal,
  llvm::getCoverageUnusedNamesVarName());
   }
+  const StringRef VarName(INSTR_PROF_QUOTE(INSTR_PROF_RAW_VERSION_VAR));
+  llvm::Type *IntTy64 = llvm::Type::getInt64Ty(Ctx);
+  uint64_t ProfileVersion = INSTR_PROF_RAW_VERSION;
+  if (llvm::ProfileCorrelate == llvm::InstrProfCorrelator::BINARY)
+ProfileVersion |= VARIANT_MASK_BIN_CORRELATE;
+  auto *VersionVariable = new llvm::GlobalVariable(
+  CGM.getModule(), llvm::Type::getInt64Ty(Ctx), true,
+  llvm::GlobalValue::WeakAnyLinkage,
+  llvm::Constant::getIntegerValue(IntTy64, llvm::APInt(64, 
ProfileVersion)),
+  VarName);
+  VersionVariable->setVisibility(llvm::GlobalValue::HiddenVisibility);
+  llvm::Triple TT(CGM.getModule().getTargetTriple());
+  if (TT.supportsCOMDAT()) {

ZequanWu wrote:

Not applicable. Removed changes in Clang.

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


[llvm] [clang] [flang] [clang-tools-extra] [lldb] [compiler-rt] [mlir] [Profile] Add binary profile correlation to offload profile metadata at runtime. (PR #69493)

2023-11-15 Thread Zequan Wu via cfe-commits


@@ -0,0 +1,46 @@
+// REQUIRES: linux || windows

ZequanWu wrote:

I think lld is not require, removed `-fuse-ld=lld`.

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


[clang-tools-extra] [compiler-rt] [lldb] [llvm] [clang] [flang] [mlir] [Profile] Add binary profile correlation to offload profile metadata at runtime. (PR #69493)

2023-11-15 Thread Zequan Wu via cfe-commits


@@ -0,0 +1,9 @@
+// RUN: %clang_cc1  -fprofile-instrument=clang -fcoverage-mapping -emit-llvm 
-o - %s | FileCheck %s
+// RUN: %clang_cc1 -mllvm -profile-correlate=binary -fprofile-instrument=clang 
-fcoverage-mapping -emit-llvm -o - %s | FileCheck %s 
--check-prefix=BIN-CORRELATE

ZequanWu wrote:

Not applicable. Removed changes in Clang.

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


[compiler-rt] [clang] [llvm] [clang-tools-extra] [lldb] [mlir] [flang] [Profile] Add binary profile correlation to offload profile metadata at runtime. (PR #69493)

2023-11-15 Thread Zequan Wu via cfe-commits


@@ -0,0 +1,11 @@
+; RUN: opt < %s -passes=instrprof -profile-correlate=binary -S | FileCheck %s

ZequanWu wrote:

Moved the test to `coverage.ll`

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


[flang] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [mlir] [clang] [Profile] Add binary profile correlation to offload profile metadata at runtime. (PR #69493)

2023-11-15 Thread Zequan Wu via cfe-commits

https://github.com/ZequanWu edited 
https://github.com/llvm/llvm-project/pull/69493
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Supports viewing class member variables in lambda when using the vs debugger (PR #71564)

2023-11-14 Thread Zequan Wu via cfe-commits


@@ -0,0 +1,48 @@
+// RUN: %clang_cl --target=x86_64-windows-msvc /c /Z7 -o %t.obj -- %s
+// RUN: llvm-pdbutil dump -all %t.obj | FileCheck %s
+
+class Foo {
+ public:
+  void foo() {
+int aa = 4;
+int bb = 5;
+int cc = 6;
+auto f = [=] {
+  int aaa = a + aa;
+  int bbb = b + bb;
+  int ccc = c + cc;
+};
+f();
+  }
+
+ private:
+  int a = 1;
+  int b = 2;
+  int c = 3;
+};
+
+int main() {
+  Foo f;
+  f.foo();
+
+  return 0;
+}
+
+// CHECK:   Types (.debug$T)
+// CHECK-NEXT: 
+// CHECK:[[FooIndex:0x[^ ]*]] | LF_CLASS [size = 36] `Foo`
+// CHECK: unique name: `.?AVFoo@@`
+// CHECK:[[FooIndex:0x[^ ]*]] | LF_FIELDLIST [size = 52]

ZequanWu wrote:

Nit: You are creating multiple `FooIndex` but not using it. The purpose of 
regex string substitution is to capture a pattern that will show up later. 
Different patterns should have different names. Here, it could be 
`[[FooFieldIndex:0x[^ ]*]]` In order to use the patterns later, use 
`0x[[FooFieldIndex]]`. Same applies to other indexes.

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


[llvm] [compiler-rt] [clang] [Profile] Refactor profile correlation. (PR #70856)

2023-11-10 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

Chatted with @MaskRay offline, we come to an agreement that it's not good to 
use relying on the bit in __llvm_profile_raw_version to decide whether or not 
to dump data/name sections at runtime for the reasons mentioned above. Sent a 
PR: #71996

> Even if we have a way to fix that, we still need the mode bit at llvm-profile 
> merging step to indicate if the raw profile need debug info/binary to 
> correlate. However, we can get ride of the runtime checking 
> __llvm_profile_has_correlation to allow code compiled w/wo debug-info linked 
> together works well.

I take back this word. When we do `llvm-profdata merge`, we use `-debug-info` 
to provide debug info file for correlation and the same could apply to binary 
correlation, a different flag. So, we know which correlation mode we are using.

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


[compiler-rt] [clang-tools-extra] [llvm] [flang] [mlir] [clang] [lldb] [Profile] Add binary profile correlation to offload profile metadata at runtime. (PR #69493)

2023-11-10 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

There are some discussions about this outside the PR:
https://github.com/llvm/llvm-project/pull/70856#issuecomment-1791465183
https://discourse.llvm.org/t/rfc-add-binary-profile-correlation-to-not-load-profile-metadata-sections-into-memory-at-runtime/74565/8

Some further discussion/pre-work needed before proceeding with this PR.

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


[clang] [compiler-rt] [llvm] [Profile] Refactor profile correlation. (PR #70856)

2023-11-08 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

> If you omit the data and names sections from the object files, then 
> __llvm_profile_end_data() - __llvm_profile_begin_data() and 
> __llvm_profile_end_names() - __llvm_profile_begin_names() are both 0 and 
> there's no need for [special casing this in the 
> runtime](https://github.com/llvm/llvm-project/blob/24b11ba24da3e65f718391ccc85d4d22a081e893/compiler-rt/lib/profile/InstrProfilingBuffer.c#L59).

>From my experiments, I found that for debug info correlation 
>`__llvm_profile_end_data()` - `__llvm_profile_begin_data()` and 
>`__llvm_profile_end_names()` - `__llvm_profile_begin_names()` are both 0 at 
>runtime because `{__start_/__stop_}{__llvm_prf_names/data}` symbols are null 
>if there is no `__llvm_prf_names/data`. 

But for binary correlation, even though `__llvm_prf_names/data` don't have 
`SHF_ALLOC` flag so they are not loaded into memory, 
`__llvm_profile_end_data()` - `__llvm_profile_begin_data()` and 
`__llvm_profile_end_names()` - `__llvm_profile_begin_names()` still produces 
the size of name and data sections, that's why we need a bit in the global 
profile version variable to indicate they are empty at runtime. I feel like 
this is a bug in lld as __start_/__stop_ symbols for non allocated sections 
should be null. Even if we have a way to fix that, we still need the mode bit 
at llvm-profile merging step to indicate if the raw profile need debug 
info/binary to correlate. However, we can get ride of the runtime checking 
`__llvm_profile_has_correlation` to allow code compiled w/wo debug-info linked 
together works well.

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


[clang] [lldb] [mlir] [compiler-rt] [llvm] [clang-tools-extra] [flang] [Profile] Add binary profile correlation to offload profile metadata at runtime. (PR #69493)

2023-11-06 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

Ping.

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


[compiler-rt] [llvm] [clang] [Profile] Refactor profile correlation. (PR #70856)

2023-11-02 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

> I'm a bit concerned about the use of hasCorrelation. We require the runtime 
> to check the flag and omit the data and names section if set which introduces 
> a potential issue: since we emit the version in every TU and u se COMDAT to 
> deduplicate them, but that means that if you link together TUs compiled with 
> and without -debug-info-correlate/-profile-correlate= (that is having 
> different flags), you would end up with different results depending on which 
> section was selected by the linker. This may not be an issue if you always 
> compile all code yourself using the same set of flags, but might be an issue 
> when you combine libraries coming from different sources.

I understand your concern. I think that's the limitation of these modes. You 
need to either compile all code with 
`-debug-info-correlate`/`-profile-correlate=` consistently or not. So, these 
modes are not suitable for projects which link with libraries compiled without 
the flags.

> What I think would be a better design is to just omit the respective sections 
> altogether when -debug-info-correlate/-profile-correlate= is enabled.

I don't understand how this solves the problem you described above. Can you 
elaborate a bit more? We still need to decide if we need to omit data and names 
sections at runtime right?

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


[llvm] [lldb] [mlir] [flang] [clang-tools-extra] [clang] [compiler-rt] [Profile] Add binary profile correlation to offload profile metadata at runtime. (PR #69493)

2023-11-02 Thread Zequan Wu via cfe-commits

https://github.com/ZequanWu updated 
https://github.com/llvm/llvm-project/pull/69493

>From 3a394ce5d4d7d91251337bd0a2c1c1a074eb37e6 Mon Sep 17 00:00:00 2001
From: Zequan Wu 
Date: Tue, 17 Oct 2023 19:24:12 -0400
Subject: [PATCH 1/6] [Profile] Add binary profile correlation.

---
 clang/lib/CodeGen/BackendUtil.cpp |  10 +-
 clang/lib/CodeGen/CoverageMappingGen.cpp  |  20 ++
 .../CodeGen/coverage-profile-raw-version.c|   9 +
 compiler-rt/include/profile/InstrProfData.inc |   2 +
 compiler-rt/lib/profile/InstrProfiling.h  |   3 +
 .../lib/profile/InstrProfilingBuffer.c|  14 ++
 compiler-rt/lib/profile/InstrProfilingMerge.c |   8 +-
 .../profile/InstrProfilingPlatformWindows.c   |   2 -
 .../lib/profile/InstrProfilingWriter.c|  24 +--
 compiler-rt/test/CMakeLists.txt   |   5 +-
 .../Darwin/instrprof-debug-info-correlate.c   |   4 +-
 .../instrprof-debug-info-correlate-warnings.c |   2 +-
 .../Linux/instrprof-debug-info-correlate.c|   6 +-
 .../instrprof-show-debug-info-correlation.c   |   6 +-
 .../test/profile/instrprof-binary-correlate.c |  29 +++
 llvm/include/llvm/ProfileData/InstrProf.h |   6 +-
 .../llvm/ProfileData/InstrProfCorrelator.h|  59 -
 .../llvm/ProfileData/InstrProfData.inc|   2 +
 .../llvm/ProfileData/InstrProfReader.h|  10 +
 .../Instrumentation/PGOInstrumentation.h  |   2 -
 .../CodeGen/TargetLoweringObjectFileImpl.cpp  |  23 +-
 .../Coverage/CoverageMappingReader.cpp|  28 ++-
 llvm/lib/ProfileData/InstrProf.cpp|   8 +-
 llvm/lib/ProfileData/InstrProfCorrelator.cpp  | 203 ++
 llvm/lib/ProfileData/InstrProfReader.cpp  |   8 +-
 .../Instrumentation/InstrProfiling.cpp|  31 +--
 .../Instrumentation/PGOInstrumentation.cpp|   3 +-
 .../debug-info-correlate-coverage.ll  |   2 +-
 .../InstrProfiling/debug-info-correlate.ll|   2 +-
 llvm/tools/llvm-profdata/llvm-profdata.cpp|  37 +++-
 30 files changed, 436 insertions(+), 132 deletions(-)
 create mode 100644 clang/test/CodeGen/coverage-profile-raw-version.c
 create mode 100644 compiler-rt/test/profile/instrprof-binary-correlate.c

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 70accce456d3c07..dad3c9a145b5049 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -42,6 +42,7 @@
 #include "llvm/Passes/PassBuilder.h"
 #include "llvm/Passes/PassPlugin.h"
 #include "llvm/Passes/StandardInstrumentations.h"
+#include "llvm/ProfileData/InstrProfCorrelator.h"
 #include "llvm/Support/BuryPointer.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -98,13 +99,16 @@ extern cl::opt PrintPipelinePasses;
 static cl::opt ClSanitizeOnOptimizerEarlyEP(
 "sanitizer-early-opt-ep", cl::Optional,
 cl::desc("Insert sanitizers on OptimizerEarlyEP."), cl::init(false));
-}
+
+extern cl::opt ProfileCorrelate;
+} // namespace llvm
 
 namespace {
 
 // Default filename used for profile generation.
 std::string getDefaultProfileGenName() {
-  return DebugInfoCorrelate ? "default_%m.proflite" : "default_%m.profraw";
+  return ProfileCorrelate.getNumOccurrences() ? "default_%m.proflite"
+  : "default_%m.profraw";
 }
 
 class EmitAssemblyHelper {
@@ -197,7 +201,7 @@ class EmitAssemblyHelper {
   void EmitAssembly(BackendAction Action,
 std::unique_ptr OS);
 };
-}
+} // namespace
 
 static SanitizerCoverageOptions
 getSancovOptsFromCGOpts(const CodeGenOptions ) {
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 76ed10091b025be..daff0d1d50923f5 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -31,6 +31,10 @@
 // is textually included.
 #define COVMAP_V3
 
+namespace llvm {
+extern cl::opt ProfileCorrelate;
+} // namespace llvm
+
 static llvm::cl::opt EmptyLineCommentCoverage(
 "emptyline-comment-coverage",
 llvm::cl::desc("Emit emptylines and comment lines as skipped regions (only 
"
@@ -1831,6 +1835,22 @@ void CoverageMappingModuleGen::emit() {
  llvm::GlobalValue::InternalLinkage, NamesArrVal,
  llvm::getCoverageUnusedNamesVarName());
   }
+  const StringRef VarName(INSTR_PROF_QUOTE(INSTR_PROF_RAW_VERSION_VAR));
+  llvm::Type *IntTy64 = llvm::Type::getInt64Ty(Ctx);
+  uint64_t ProfileVersion = INSTR_PROF_RAW_VERSION;
+  if (llvm::ProfileCorrelate == llvm::InstrProfCorrelator::BINARY)
+ProfileVersion |= VARIANT_MASK_BIN_CORRELATE;
+  auto *VersionVariable = new llvm::GlobalVariable(
+  CGM.getModule(), llvm::Type::getInt64Ty(Ctx), true,
+  llvm::GlobalValue::WeakAnyLinkage,
+  llvm::Constant::getIntegerValue(IntTy64, llvm::APInt(64, 
ProfileVersion)),
+  VarName);
+  VersionVariable->setVisibility(llvm::GlobalValue::HiddenVisibility);
+  llvm::Triple 

[clang] [llvm] [mlir] [flang] [compiler-rt] [clang-tools-extra] [lldb] [Profile] Add binary profile correlation to offload profile metadata at runtime. (PR #69493)

2023-11-02 Thread Zequan Wu via cfe-commits

https://github.com/ZequanWu updated 
https://github.com/llvm/llvm-project/pull/69493

>From 3a394ce5d4d7d91251337bd0a2c1c1a074eb37e6 Mon Sep 17 00:00:00 2001
From: Zequan Wu 
Date: Tue, 17 Oct 2023 19:24:12 -0400
Subject: [PATCH 1/5] [Profile] Add binary profile correlation.

---
 clang/lib/CodeGen/BackendUtil.cpp |  10 +-
 clang/lib/CodeGen/CoverageMappingGen.cpp  |  20 ++
 .../CodeGen/coverage-profile-raw-version.c|   9 +
 compiler-rt/include/profile/InstrProfData.inc |   2 +
 compiler-rt/lib/profile/InstrProfiling.h  |   3 +
 .../lib/profile/InstrProfilingBuffer.c|  14 ++
 compiler-rt/lib/profile/InstrProfilingMerge.c |   8 +-
 .../profile/InstrProfilingPlatformWindows.c   |   2 -
 .../lib/profile/InstrProfilingWriter.c|  24 +--
 compiler-rt/test/CMakeLists.txt   |   5 +-
 .../Darwin/instrprof-debug-info-correlate.c   |   4 +-
 .../instrprof-debug-info-correlate-warnings.c |   2 +-
 .../Linux/instrprof-debug-info-correlate.c|   6 +-
 .../instrprof-show-debug-info-correlation.c   |   6 +-
 .../test/profile/instrprof-binary-correlate.c |  29 +++
 llvm/include/llvm/ProfileData/InstrProf.h |   6 +-
 .../llvm/ProfileData/InstrProfCorrelator.h|  59 -
 .../llvm/ProfileData/InstrProfData.inc|   2 +
 .../llvm/ProfileData/InstrProfReader.h|  10 +
 .../Instrumentation/PGOInstrumentation.h  |   2 -
 .../CodeGen/TargetLoweringObjectFileImpl.cpp  |  23 +-
 .../Coverage/CoverageMappingReader.cpp|  28 ++-
 llvm/lib/ProfileData/InstrProf.cpp|   8 +-
 llvm/lib/ProfileData/InstrProfCorrelator.cpp  | 203 ++
 llvm/lib/ProfileData/InstrProfReader.cpp  |   8 +-
 .../Instrumentation/InstrProfiling.cpp|  31 +--
 .../Instrumentation/PGOInstrumentation.cpp|   3 +-
 .../debug-info-correlate-coverage.ll  |   2 +-
 .../InstrProfiling/debug-info-correlate.ll|   2 +-
 llvm/tools/llvm-profdata/llvm-profdata.cpp|  37 +++-
 30 files changed, 436 insertions(+), 132 deletions(-)
 create mode 100644 clang/test/CodeGen/coverage-profile-raw-version.c
 create mode 100644 compiler-rt/test/profile/instrprof-binary-correlate.c

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 70accce456d3c07..dad3c9a145b5049 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -42,6 +42,7 @@
 #include "llvm/Passes/PassBuilder.h"
 #include "llvm/Passes/PassPlugin.h"
 #include "llvm/Passes/StandardInstrumentations.h"
+#include "llvm/ProfileData/InstrProfCorrelator.h"
 #include "llvm/Support/BuryPointer.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -98,13 +99,16 @@ extern cl::opt PrintPipelinePasses;
 static cl::opt ClSanitizeOnOptimizerEarlyEP(
 "sanitizer-early-opt-ep", cl::Optional,
 cl::desc("Insert sanitizers on OptimizerEarlyEP."), cl::init(false));
-}
+
+extern cl::opt ProfileCorrelate;
+} // namespace llvm
 
 namespace {
 
 // Default filename used for profile generation.
 std::string getDefaultProfileGenName() {
-  return DebugInfoCorrelate ? "default_%m.proflite" : "default_%m.profraw";
+  return ProfileCorrelate.getNumOccurrences() ? "default_%m.proflite"
+  : "default_%m.profraw";
 }
 
 class EmitAssemblyHelper {
@@ -197,7 +201,7 @@ class EmitAssemblyHelper {
   void EmitAssembly(BackendAction Action,
 std::unique_ptr OS);
 };
-}
+} // namespace
 
 static SanitizerCoverageOptions
 getSancovOptsFromCGOpts(const CodeGenOptions ) {
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 76ed10091b025be..daff0d1d50923f5 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -31,6 +31,10 @@
 // is textually included.
 #define COVMAP_V3
 
+namespace llvm {
+extern cl::opt ProfileCorrelate;
+} // namespace llvm
+
 static llvm::cl::opt EmptyLineCommentCoverage(
 "emptyline-comment-coverage",
 llvm::cl::desc("Emit emptylines and comment lines as skipped regions (only 
"
@@ -1831,6 +1835,22 @@ void CoverageMappingModuleGen::emit() {
  llvm::GlobalValue::InternalLinkage, NamesArrVal,
  llvm::getCoverageUnusedNamesVarName());
   }
+  const StringRef VarName(INSTR_PROF_QUOTE(INSTR_PROF_RAW_VERSION_VAR));
+  llvm::Type *IntTy64 = llvm::Type::getInt64Ty(Ctx);
+  uint64_t ProfileVersion = INSTR_PROF_RAW_VERSION;
+  if (llvm::ProfileCorrelate == llvm::InstrProfCorrelator::BINARY)
+ProfileVersion |= VARIANT_MASK_BIN_CORRELATE;
+  auto *VersionVariable = new llvm::GlobalVariable(
+  CGM.getModule(), llvm::Type::getInt64Ty(Ctx), true,
+  llvm::GlobalValue::WeakAnyLinkage,
+  llvm::Constant::getIntegerValue(IntTy64, llvm::APInt(64, 
ProfileVersion)),
+  VarName);
+  VersionVariable->setVisibility(llvm::GlobalValue::HiddenVisibility);
+  llvm::Triple 

[compiler-rt] [llvm] [clang] [Profile] Refactor profile correlation. (PR #70856)

2023-11-02 Thread Zequan Wu via cfe-commits


@@ -89,3 +89,7 @@ COMPILER_RT_VISIBILITY void 
__llvm_profile_reset_counters(void) {
   }
   lprofSetProfileDumped(0);
 }
+
+inline int hasCorrelation() {

ZequanWu wrote:

COMPILER_RT_VISIBILITY is added at 
https://github.com/llvm/llvm-project/commit/56e205a89cbb114750f2bd3f5cfbd19e209d018a.

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


[clang] [llvm] [compiler-rt] [Profile] Refactor profile correlation. (PR #70856)

2023-11-02 Thread Zequan Wu via cfe-commits


@@ -261,6 +261,9 @@ uint64_t __llvm_profile_get_magic(void);
 /*! \brief Get the version of the file format. */
 uint64_t __llvm_profile_get_version(void);
 
+/*! \brief If the binary is compiled with profile correlation. */
+int hasCorrelation();

ZequanWu wrote:

Renamed to `__llvm_profile_has_correlation` at 
https://github.com/llvm/llvm-project/commit/7fa9930847bbef4319c2d2e9c782eb5c8e6b1892

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


[clang] [llvm] [compiler-rt] [Profile] Refactor profile correlation. (PR #70856)

2023-11-02 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

> > Sounds fine to me, but I guess I don't understand why `-profile-correlate=` 
> > doesn't work. Do you still plan to add the flag later?
> 
> I haven't found a way to share information (whether of not binary correlation 
> is enabled) between CodeGen(TargetLoweringObjectFileImpl.cpp) and 
> Instrumentation(InstrProfiling.cpp) components. The explanation is here: 
> https://discourse.llvm.org/t/rfc-add-binary-profile-correlation-to-not-load-profile-metadata-sections-into-memory-at-runtime/74565#use-temporary-section-names-6.

Oh, actually, we can have -profile-correlate flag just need to define it at 
InstrProfCorrelator.cpp (ProfileData component), which is less desired but 
working as discussed at 
https://github.com/llvm/llvm-project/pull/69656#discussion_r1372179620. 

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


[compiler-rt] [llvm] [clang] [Profile] Refactor profile correlation. (PR #70856)

2023-11-02 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

> @ZequanWu this seems to cause issues on macOS: 
> https://green.lab.llvm.org/green/job/clang-stage1-RA/36184/console
> 
> ```
> Profile-x86_64 :: Darwin/instrprof-debug-info-correlate.c
> Profile-x86_64 :: instrprof-darwin-
> Profile-x86_64h :: Darwin/instrprof-debug-info-correlate.c
> Profile-x86_64h :: instrprof-darwin-exports.c
> ```
> 
> are failing, could you please take a look or revert?

It should be fixed by 
https://github.com/llvm/llvm-project/commit/56e205a89cbb114750f2bd3f5cfbd19e209d018a.

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


[compiler-rt] [llvm] [clang] [Profile] Refactor profile correlation. (PR #70856)

2023-11-01 Thread Zequan Wu via cfe-commits

https://github.com/ZequanWu closed 
https://github.com/llvm/llvm-project/pull/70856
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [llvm] [Profile] Refactor profile correlation. (PR #70856)

2023-11-01 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

> Sounds fine to me, but I guess I don't understand why `-profile-correlate=` 
> doesn't work. Do you still plan to add the flag later?

I haven't found a way to share information (whether of not binary correlation 
is enabled) between CodeGen(TargetLoweringObjectFileImpl.cpp) and 
Instrumentation(InstrProfiling.cpp) components. The explanation is 
here: 
https://discourse.llvm.org/t/rfc-add-binary-profile-correlation-to-not-load-profile-metadata-sections-into-memory-at-runtime/74565#use-temporary-section-names-6.

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


[llvm] [clang] [clang-tools-extra] [llvm-profdata] Emit warning when counter value is greater than 2^56. (PR #69513)

2023-11-01 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

> Just to double check: the commit message says "emit warning", but it should 
> error by default, right?

Yes, -failure-mode=any is default, which throws an error if there is any.

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


[clang] [llvm] [compiler-rt] [Profile] Refactor profile correlation. (PR #70856)

2023-10-31 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

Sorry for so many noise regarding this change.

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


[clang] [llvm] [clang-tools-extra] [llvm-profdata] Emit warning when counter value is greater than 2^56. (PR #69513)

2023-10-31 Thread Zequan Wu via cfe-commits

https://github.com/ZequanWu closed 
https://github.com/llvm/llvm-project/pull/69513
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [clang-tools-extra] [llvm-profdata] Emit warning when counter value is greater than 2^56. (PR #69513)

2023-10-31 Thread Zequan Wu via cfe-commits

https://github.com/ZequanWu updated 
https://github.com/llvm/llvm-project/pull/69513

>From 9a1af6e1d47ab622979796f2319edec8a9c77928 Mon Sep 17 00:00:00 2001
From: Zequan Wu 
Date: Wed, 18 Oct 2023 16:28:30 -0400
Subject: [PATCH 1/7] [llvm-profdata] Emit error when counter value is greater
 than 2^56.

---
 llvm/lib/ProfileData/InstrProfReader.cpp| 13 +++--
 .../malformed-num-counters-zero.test| 17 +++--
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/ProfileData/InstrProfReader.cpp 
b/llvm/lib/ProfileData/InstrProfReader.cpp
index a920a31d0a4b229..d62a816cdeed4e6 100644
--- a/llvm/lib/ProfileData/InstrProfReader.cpp
+++ b/llvm/lib/ProfileData/InstrProfReader.cpp
@@ -38,6 +38,9 @@
 
 using namespace llvm;
 
+// Maxium counter value 2^56.
+static uint64_t MaxCounterValue = 0xff;
+
 // Extracts the variant information from the top 32 bits in the version and
 // returns an enum specifying the variants present.
 static InstrProfKind getProfileKindFromVersion(uint64_t Version) {
@@ -676,8 +679,14 @@ Error RawInstrProfReader::readRawCounts(
   // A value of zero signifies the block is covered.
   Record.Counts.push_back(*Ptr == 0 ? 1 : 0);
 } else {
-  const auto *CounterValue = reinterpret_cast(Ptr);
-  Record.Counts.push_back(swap(*CounterValue));
+  uint64_t CounterValue = swap(*reinterpret_cast(Ptr));
+  if (CounterValue > MaxCounterValue)
+return error(instrprof_error::malformed,
+ ("counter value " + Twine(CounterValue) +
+  " is greater than " + Twine(MaxCounterValue))
+ .str());
+
+  Record.Counts.push_back(CounterValue);
 }
   }
 
diff --git a/llvm/test/tools/llvm-profdata/malformed-num-counters-zero.test 
b/llvm/test/tools/llvm-profdata/malformed-num-counters-zero.test
index b718cf0fd8e9723..011c1cbf73af3bb 100644
--- a/llvm/test/tools/llvm-profdata/malformed-num-counters-zero.test
+++ b/llvm/test/tools/llvm-profdata/malformed-num-counters-zero.test
@@ -35,11 +35,24 @@ RUN: printf '\1\0\0\0\0\0\0\0' >> %t.profraw
 RUN: printf '\0\0\4\0\1\0\0\0' >> %t.profraw
 RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
 RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
+
+// Make a copy for another test.
+RUN: cp %t.profraw %t1.profraw
+
 // Make NumCounters = 0 so that we get "number of counters is zero" error 
message
 RUN: printf '\0\0\0\0\0\0\0\0' >> %t.profraw
 
 RUN: printf '\023\0\0\0\0\0\0\0' >> %t.profraw
 RUN: printf '\3\0foo\0\0\0' >> %t.profraw
 
-RUN: not llvm-profdata show %t.profraw 2>&1 | FileCheck %s
-CHECK: malformed instrumentation profile data: number of counters is zero
+RUN: not llvm-profdata show %t.profraw 2>&1 | FileCheck %s --check-prefix=ZERO
+ZERO: malformed instrumentation profile data: number of counters is zero
+
+// Test a counter value greater than 2^56.
+RUN: printf '\1\0\0\0\0\0\0\0' >> %t1.profraw
+
+RUN: printf '\0\0\0\0\0\0\0\1' >> %t1.profraw
+RUN: printf '\3\0foo\0\0\0' >> %t1.profraw
+
+RUN: not llvm-profdata show %t1.profraw 2>&1 | FileCheck %s --check-prefix=MAX
+MAX: malformed instrumentation profile data: counter value 72057594037927936 
is greater than 72057594037927935

>From 5d4c2ce9b8f5c49041bcbdf12f7890f75e4754c7 Mon Sep 17 00:00:00 2001
From: Zequan Wu 
Date: Thu, 19 Oct 2023 15:41:38 -0400
Subject: [PATCH 2/7] address comments

---
 llvm/include/llvm/ProfileData/InstrProfReader.h|  3 +++
 llvm/lib/ProfileData/InstrProfReader.cpp   | 10 +++---
 .../llvm-profdata/malformed-num-counters-zero.test |  6 +++---
 3 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/llvm/include/llvm/ProfileData/InstrProfReader.h 
b/llvm/include/llvm/ProfileData/InstrProfReader.h
index 5f54cbeb1b01eda..e62ee42d09f4145 100644
--- a/llvm/include/llvm/ProfileData/InstrProfReader.h
+++ b/llvm/include/llvm/ProfileData/InstrProfReader.h
@@ -341,6 +341,9 @@ class RawInstrProfReader : public InstrProfReader {
   /// Start address of binary id length and data pairs.
   const uint8_t *BinaryIdsStart;
 
+  // Maxium counter value 2^56.
+  static const uint64_t MaxCounterValue = (1ULL << 56);
+
 public:
   RawInstrProfReader(std::unique_ptr DataBuffer,
  const InstrProfCorrelator *Correlator)
diff --git a/llvm/lib/ProfileData/InstrProfReader.cpp 
b/llvm/lib/ProfileData/InstrProfReader.cpp
index d62a816cdeed4e6..3a1d5ef3a9d827e 100644
--- a/llvm/lib/ProfileData/InstrProfReader.cpp
+++ b/llvm/lib/ProfileData/InstrProfReader.cpp
@@ -27,6 +27,7 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/SwapByteOrder.h"
 #include "llvm/Support/VirtualFileSystem.h"
+#include "llvm/Support/WithColor.h"
 #include 
 #include 
 #include 
@@ -38,9 +39,6 @@
 
 using namespace llvm;
 
-// Maxium counter value 2^56.
-static uint64_t MaxCounterValue = 0xff;
-
 // Extracts the variant information from the top 32 bits in the version and
 // returns an enum 

[clang] [llvm] [compiler-rt] [Profile] Refactor profile correlation. (PR #70856)

2023-10-31 Thread Zequan Wu via cfe-commits

https://github.com/ZequanWu created 
https://github.com/llvm/llvm-project/pull/70856

Refactor some code from https://github.com/llvm/llvm-project/pull/69493.

#70712 was reverted due to linking failures. So, I removed 
`-profile-correlate=` flag and kept `-debug-info-correlate` in this change. 

>From e33d4e7d8324e8efb6f0c0ff5f3426a2e0a51ee1 Mon Sep 17 00:00:00 2001
From: Zequan Wu 
Date: Mon, 30 Oct 2023 15:45:08 -0400
Subject: [PATCH 1/4] Refactor profile correlation.

---
 clang/lib/CodeGen/BackendUtil.cpp |  14 ++-
 compiler-rt/lib/profile/InstrProfiling.c  |   4 +
 compiler-rt/lib/profile/InstrProfiling.h  |   6 ++
 .../lib/profile/InstrProfilingBuffer.c|  11 ++
 compiler-rt/lib/profile/InstrProfilingMerge.c |  11 +-
 .../lib/profile/InstrProfilingWriter.c|  21 ++--
 .../Darwin/instrprof-debug-info-correlate.c   |   4 +-
 .../instrprof-debug-info-correlate-warnings.c |   2 +-
 .../Linux/instrprof-debug-info-correlate.c|   6 +-
 .../instrprof-show-debug-info-correlation.c   |   6 +-
 llvm/docs/CommandGuide/llvm-profdata.rst  |   4 +-
 .../llvm/ProfileData/InstrProfCorrelator.h|  13 ++-
 .../llvm/ProfileData/InstrProfReader.h|   2 +
 .../Instrumentation/PGOInstrumentation.h  |   2 -
 .../CodeGen/TargetLoweringObjectFileImpl.cpp  |  19 
 llvm/lib/ProfileData/InstrProfCorrelator.cpp  | 100 +++---
 llvm/lib/ProfileData/InstrProfReader.cpp  |   4 +-
 .../Instrumentation/InstrProfiling.cpp|  18 ++--
 .../Instrumentation/PGOInstrumentation.cpp|   6 +-
 .../debug-info-correlate-coverage.ll  |   2 +-
 .../InstrProfiling/debug-info-correlate.ll|   2 +-
 llvm/tools/llvm-profdata/llvm-profdata.cpp|   9 +-
 22 files changed, 176 insertions(+), 90 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 70accce456d3c07..83b81a38a768523 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -42,6 +42,7 @@
 #include "llvm/Passes/PassBuilder.h"
 #include "llvm/Passes/PassPlugin.h"
 #include "llvm/Passes/StandardInstrumentations.h"
+#include "llvm/ProfileData/InstrProfCorrelator.h"
 #include "llvm/Support/BuryPointer.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -55,6 +56,7 @@
 #include "llvm/Target/TargetOptions.h"
 #include "llvm/TargetParser/SubtargetFeature.h"
 #include "llvm/TargetParser/Triple.h"
+#include "llvm/Transforms/HipStdPar/HipStdPar.h"
 #include "llvm/Transforms/IPO/EmbedBitcodePass.h"
 #include "llvm/Transforms/IPO/LowerTypeTests.h"
 #include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h"
@@ -78,7 +80,6 @@
 #include "llvm/Transforms/Scalar/EarlyCSE.h"
 #include "llvm/Transforms/Scalar/GVN.h"
 #include "llvm/Transforms/Scalar/JumpThreading.h"
-#include "llvm/Transforms/HipStdPar/HipStdPar.h"
 #include "llvm/Transforms/Utils/Debugify.h"
 #include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
 #include "llvm/Transforms/Utils/ModuleUtils.h"
@@ -98,13 +99,18 @@ extern cl::opt PrintPipelinePasses;
 static cl::opt ClSanitizeOnOptimizerEarlyEP(
 "sanitizer-early-opt-ep", cl::Optional,
 cl::desc("Insert sanitizers on OptimizerEarlyEP."), cl::init(false));
-}
+
+extern cl::opt DebugInfoCorrelate;
+extern cl::opt ProfileCorrelate;
+} // namespace llvm
 
 namespace {
 
 // Default filename used for profile generation.
 std::string getDefaultProfileGenName() {
-  return DebugInfoCorrelate ? "default_%m.proflite" : "default_%m.profraw";
+  return DebugInfoCorrelate || ProfileCorrelate != InstrProfCorrelator::NONE
+ ? "default_%m.proflite"
+ : "default_%m.profraw";
 }
 
 class EmitAssemblyHelper {
@@ -197,7 +203,7 @@ class EmitAssemblyHelper {
   void EmitAssembly(BackendAction Action,
 std::unique_ptr OS);
 };
-}
+} // namespace
 
 static SanitizerCoverageOptions
 getSancovOptsFromCGOpts(const CodeGenOptions ) {
diff --git a/compiler-rt/lib/profile/InstrProfiling.c 
b/compiler-rt/lib/profile/InstrProfiling.c
index da04d8ebdec95bb..7d69e37815c948f 100644
--- a/compiler-rt/lib/profile/InstrProfiling.c
+++ b/compiler-rt/lib/profile/InstrProfiling.c
@@ -89,3 +89,7 @@ COMPILER_RT_VISIBILITY void 
__llvm_profile_reset_counters(void) {
   }
   lprofSetProfileDumped(0);
 }
+
+inline int hasCorrelation() {
+  return (__llvm_profile_get_version() & VARIANT_MASK_DBG_CORRELATE) != 0ULL;
+}
diff --git a/compiler-rt/lib/profile/InstrProfiling.h 
b/compiler-rt/lib/profile/InstrProfiling.h
index e143149fca82707..b8104af5f12b910 100644
--- a/compiler-rt/lib/profile/InstrProfiling.h
+++ b/compiler-rt/lib/profile/InstrProfiling.h
@@ -261,6 +261,9 @@ uint64_t __llvm_profile_get_magic(void);
 /*! \brief Get the version of the file format. */
 uint64_t __llvm_profile_get_version(void);
 
+/*! \brief If the binary is compiled with profile correlation. */
+int hasCorrelation();
+
 /*! \brief Get the number of entries in the profile data section. */
 uint64_t 

[clang] [clang-tools-extra] [llvm] [llvm-profdata] Emit warning when counter value is greater than 2^56. (PR #69513)

2023-10-31 Thread Zequan Wu via cfe-commits

ZequanWu wrote:

Ping.

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


  1   2   3   >