[PATCH] D82904: [clang-tidy] Warn pointer captured in async block

2020-07-01 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 274855.
ellis added a comment.

Add `isLanguageVersionSupported` for Objective-C


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82904/new/

https://reviews.llvm.org/D82904

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/NoEscapeCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/NoEscapeCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-no-escape.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-no-escape.m

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-no-escape.m
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-no-escape.m
@@ -0,0 +1,27 @@
+// RUN: %check_clang_tidy %s bugprone-no-escape %t
+
+typedef struct dispatch_queue_s *dispatch_queue_t;
+typedef struct dispatch_time_s *dispatch_time_t;
+typedef void (^dispatch_block_t)(void);
+void dispatch_async(dispatch_queue_t queue, dispatch_block_t block);
+void dispatch_after(dispatch_time_t when, dispatch_queue_t queue, dispatch_block_t block);
+
+extern dispatch_queue_t queue;
+
+void test_noescape_attribute(__attribute__((noescape)) int *p, int *q) {
+  dispatch_async(queue, ^{
+*p = 123;
+// CHECK-MESSAGES: :[[@LINE-2]]:25: warning: pointer 'p' with attribute 'noescape' is captured by an asynchronously-executed block [bugprone-no-escape]
+// CHECK-MESSAGES: :[[@LINE-4]]:30: note: the 'noescape' attribute is declared here.
+  });
+
+  dispatch_after(456, queue, ^{
+*p = 789;
+// CHECK-MESSAGES: :[[@LINE-2]]:30: warning: pointer 'p' with attribute 'noescape' is captured by an asynchronously-executed block [bugprone-no-escape]
+  });
+
+  dispatch_async(queue, ^{
+*q = 0;
+// CHECK-MESSAGES-NOT: :[[@LINE-2]]:25: warning: pointer 'q' with attribute 'noescape' is captured by an asynchronously-executed block
+  });
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -70,6 +70,7 @@
`bugprone-misplaced-widening-cast `_,
`bugprone-move-forwarding-reference `_, "Yes"
`bugprone-multiple-statement-macro `_,
+   `bugprone-no-escape `_, "Yes"
`bugprone-not-null-terminated-result `_, "Yes"
`bugprone-parent-virtual-call `_, "Yes"
`bugprone-posix-return `_, "Yes"
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone-no-escape.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone-no-escape.rst
@@ -0,0 +1,18 @@
+.. title:: clang-tidy - bugprone-no-escape
+
+bugprone-no-escape
+==
+
+Finds pointers with the ``noescape`` attribute that are captured by an
+asynchronously-executed block. The block arguments in ``dispatch_async()`` and
+``dispatch_after()`` are guaranteed to escape, so it is an error if a pointer with the
+``noescape`` attribute is captured by one of these blocks.
+
+The following is an example of an invalid use of the ``noescape`` attribute.
+
+  .. code-block:: objc
+void foo(__attribute__((noescape)) int *p) {
+  dispatch_async(queue, ^{
+*p = 123;
+  });
+});
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -94,6 +94,12 @@
   result of a memory allocation function (``malloc()``, ``calloc()``,
   ``realloc()``, ``alloca()``) instead of its argument.
 
+- New :doc:`bugprone-no-escape
+  ` check.
+
+  Finds pointers with the ``noescape`` attribute that are captured by an
+  asynchronously-executed block.
+
 - New :doc:`bugprone-spuriously-wake-up-functions
   ` check.
 
@@ -201,14 +207,14 @@
   Now checks ``std::basic_string_view`` by default.
 
 - Improved :doc:`readability-else-after-return
-  ` check now supports a 
+  ` check now supports a
   `WarnOnConditionVariables` option to control whether to refactor condition
   variables where possible.
 
 - Improved :doc:`readability-identifier-naming
   ` check.
 
-  Now able to rename member references in class template definitions with 
+  Now able to rename member references in class template definitions with
   explicit access.
 
 - Improved :doc:`readability-qualified-auto
Index: clang-tools-extra/clang-tidy/bugprone/NoEscapeCheck.h
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/bugprone/NoEscapeCheck.h
@@ -0,0 +1,39 @@
+//===--- NoEscapeCheck.h - clang-tidy ---*- C++ -*-===//
+//
+// Part of the 

[PATCH] D82904: [clang-tidy] Warn pointer captured in async block

2020-07-06 Thread Ellis Hoag via Phabricator via cfe-commits
ellis marked an inline comment as done.
ellis added inline comments.



Comment at: clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp:82
 "bugprone-bool-pointer-implicit-conversion");
-CheckFactories.registerCheck(
-"bugprone-branch-clone");
+CheckFactories.registerCheck("bugprone-branch-clone");
 CheckFactories.registerCheck(

aaron.ballman wrote:
> It looks like unrelated formatting changes may have snuck in?
The script `add_new_check.py` doesn't format the code that it generated so a 
few lines aren't linted. Would you like me to undo these extra formatted lines?



Comment at: clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp:121
 "bugprone-narrowing-conversions");
+CheckFactories.registerCheck("bugprone-no-escape");
 CheckFactories.registerCheck(

njames93 wrote:
> aaron.ballman wrote:
> > Given that this is limited to Objective-C, why register this under 
> > `bugprone` as opposed to the `objc` module? Alternatively, why limit to 
> > Objective-C when blocks can be used in other modes like C or C++ with 
> > `-fblocks`?
> Thats a good point, maybe restrict this to `LangOptions::ObjC || 
> LangOptions::Blocks` Then it can be left in bugprone.
Ok, I'll include `LangOptions::Blocks`.



Comment at: clang-tools-extra/clang-tidy/bugprone/NoEscapeCheck.cpp:37
+if (Var && Var->hasAttr()) {
+  diag(MatchedEscapingBlock->getBeginLoc(),
+   "pointer %0 with attribute 'noescape' is captured by an "

aaron.ballman wrote:
> Given that the capture is the issue (not the block), why not point to the use 
> of the captured variable?
I actually agree that pointing to the use of the captured variable would be 
easier to read, but honestly I couldn't figure out how to grab the location of 
that use. All I could get was the definition of the variable.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82904/new/

https://reviews.llvm.org/D82904



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


[PATCH] D82904: [clang-tidy] Warn pointer captured in async block

2020-07-06 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 275826.
ellis marked 9 inline comments as done.
ellis added a comment.

Use `LangOpts.Blocks` instead of `LangOpts.ObjC` and add FIXME about grabbing 
the use location of a `CapturedVar`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82904/new/

https://reviews.llvm.org/D82904

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/NoEscapeCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/NoEscapeCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-no-escape.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-no-escape.m

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-no-escape.m
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-no-escape.m
@@ -0,0 +1,27 @@
+// RUN: %check_clang_tidy %s bugprone-no-escape %t
+
+typedef struct dispatch_queue_s *dispatch_queue_t;
+typedef struct dispatch_time_s *dispatch_time_t;
+typedef void (^dispatch_block_t)(void);
+void dispatch_async(dispatch_queue_t queue, dispatch_block_t block);
+void dispatch_after(dispatch_time_t when, dispatch_queue_t queue, dispatch_block_t block);
+
+extern dispatch_queue_t queue;
+
+void test_noescape_attribute(__attribute__((noescape)) int *p, int *q) {
+  dispatch_async(queue, ^{
+*p = 123;
+// CHECK-MESSAGES: :[[@LINE-2]]:25: warning: pointer 'p' with attribute 'noescape' is captured by an asynchronously-executed block [bugprone-no-escape]
+// CHECK-MESSAGES: :[[@LINE-4]]:30: note: the 'noescape' attribute is declared here.
+  });
+
+  dispatch_after(456, queue, ^{
+*p = 789;
+// CHECK-MESSAGES: :[[@LINE-2]]:30: warning: pointer 'p' with attribute 'noescape' is captured by an asynchronously-executed block [bugprone-no-escape]
+  });
+
+  dispatch_async(queue, ^{
+*q = 0;
+// CHECK-MESSAGES-NOT: :[[@LINE-2]]:25: warning: pointer 'q' with attribute 'noescape' is captured by an asynchronously-executed block
+  });
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -70,6 +70,7 @@
`bugprone-misplaced-widening-cast `_,
`bugprone-move-forwarding-reference `_, "Yes"
`bugprone-multiple-statement-macro `_,
+   `bugprone-no-escape `_, "Yes"
`bugprone-not-null-terminated-result `_, "Yes"
`bugprone-parent-virtual-call `_, "Yes"
`bugprone-posix-return `_, "Yes"
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone-no-escape.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone-no-escape.rst
@@ -0,0 +1,18 @@
+.. title:: clang-tidy - bugprone-no-escape
+
+bugprone-no-escape
+==
+
+Finds pointers with the ``noescape`` attribute that are captured by an
+asynchronously-executed block. The block arguments in ``dispatch_async()`` and
+``dispatch_after()`` are guaranteed to escape, so it is an error if a pointer with the
+``noescape`` attribute is captured by one of these blocks.
+
+The following is an example of an invalid use of the ``noescape`` attribute.
+
+  .. code-block:: objc
+void foo(__attribute__((noescape)) int *p) {
+  dispatch_async(queue, ^{
+*p = 123;
+  });
+});
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -94,6 +94,12 @@
   result of a memory allocation function (``malloc()``, ``calloc()``,
   ``realloc()``, ``alloca()``) instead of its argument.
 
+- New :doc:`bugprone-no-escape
+  ` check.
+
+  Finds pointers with the ``noescape`` attribute that are captured by an
+  asynchronously-executed block.
+
 - New :doc:`bugprone-spuriously-wake-up-functions
   ` check.
 
@@ -201,14 +207,14 @@
   Now checks ``std::basic_string_view`` by default.
 
 - Improved :doc:`readability-else-after-return
-  ` check now supports a 
+  ` check now supports a
   `WarnOnConditionVariables` option to control whether to refactor condition
   variables where possible.
 
 - Improved :doc:`readability-identifier-naming
   ` check.
 
-  Now able to rename member references in class template definitions with 
+  Now able to rename member references in class template definitions with
   explicit access.
 
 - Improved :doc:`readability-qualified-auto
Index: clang-tools-extra/clang-tidy/bugprone/NoEscapeCheck.h
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/bugprone/NoEscapeCheck.h
@@ -0,0 +1,3

[PATCH] D82904: [clang-tidy] Warn pointer captured in async block

2020-07-06 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added inline comments.



Comment at: clang-tools-extra/clang-tidy/bugprone/NoEscapeCheck.cpp:34
+  const BlockDecl *EscapingBlockDecl = MatchedEscapingBlock->getBlockDecl();
+  for (const BlockDecl::Capture &CapturedVar : EscapingBlockDecl->captures()) {
+const VarDecl *Var = CapturedVar.getVariable();

aaron.ballman wrote:
> This makes me think we should extend the `hasAnyCaptures()` AST matcher so it 
> works with blocks as well as lambdas. It would be nice to do all of this from 
> the matcher interface.
Should I add a TODO for this?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82904/new/

https://reviews.llvm.org/D82904



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


[PATCH] D82904: [clang-tidy] Warn pointer captured in async block

2020-07-07 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 276095.
ellis added a comment.

Add RUN line to test in C


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82904/new/

https://reviews.llvm.org/D82904

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/NoEscapeCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/NoEscapeCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-no-escape.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-no-escape.m

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-no-escape.m
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-no-escape.m
@@ -0,0 +1,28 @@
+// RUN: %check_clang_tidy %s bugprone-no-escape %t
+// RUN: %check_clang_tidy %s -assume-filename=bugprone-no-escape.c bugprone-no-escape %t -- -- -fblocks
+
+typedef struct dispatch_queue_s *dispatch_queue_t;
+typedef struct dispatch_time_s *dispatch_time_t;
+typedef void (^dispatch_block_t)(void);
+void dispatch_async(dispatch_queue_t queue, dispatch_block_t block);
+void dispatch_after(dispatch_time_t when, dispatch_queue_t queue, dispatch_block_t block);
+
+extern dispatch_queue_t queue;
+
+void test_noescape_attribute(__attribute__((noescape)) int *p, int *q) {
+  dispatch_async(queue, ^{
+*p = 123;
+// CHECK-MESSAGES: :[[@LINE-2]]:25: warning: pointer 'p' with attribute 'noescape' is captured by an asynchronously-executed block [bugprone-no-escape]
+// CHECK-MESSAGES: :[[@LINE-4]]:30: note: the 'noescape' attribute is declared here.
+  });
+
+  dispatch_after(456, queue, ^{
+*p = 789;
+// CHECK-MESSAGES: :[[@LINE-2]]:30: warning: pointer 'p' with attribute 'noescape' is captured by an asynchronously-executed block [bugprone-no-escape]
+  });
+
+  dispatch_async(queue, ^{
+*q = 0;
+// CHECK-MESSAGES-NOT: :[[@LINE-2]]:25: warning: pointer 'q' with attribute 'noescape' is captured by an asynchronously-executed block
+  });
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -70,6 +70,7 @@
`bugprone-misplaced-widening-cast `_,
`bugprone-move-forwarding-reference `_, "Yes"
`bugprone-multiple-statement-macro `_,
+   `bugprone-no-escape `_, "Yes"
`bugprone-not-null-terminated-result `_, "Yes"
`bugprone-parent-virtual-call `_, "Yes"
`bugprone-posix-return `_, "Yes"
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone-no-escape.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone-no-escape.rst
@@ -0,0 +1,18 @@
+.. title:: clang-tidy - bugprone-no-escape
+
+bugprone-no-escape
+==
+
+Finds pointers with the ``noescape`` attribute that are captured by an
+asynchronously-executed block. The block arguments in ``dispatch_async()`` and
+``dispatch_after()`` are guaranteed to escape, so it is an error if a pointer with the
+``noescape`` attribute is captured by one of these blocks.
+
+The following is an example of an invalid use of the ``noescape`` attribute.
+
+  .. code-block:: objc
+void foo(__attribute__((noescape)) int *p) {
+  dispatch_async(queue, ^{
+*p = 123;
+  });
+});
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -94,6 +94,12 @@
   result of a memory allocation function (``malloc()``, ``calloc()``,
   ``realloc()``, ``alloca()``) instead of its argument.
 
+- New :doc:`bugprone-no-escape
+  ` check.
+
+  Finds pointers with the ``noescape`` attribute that are captured by an
+  asynchronously-executed block.
+
 - New :doc:`bugprone-spuriously-wake-up-functions
   ` check.
 
@@ -201,14 +207,14 @@
   Now checks ``std::basic_string_view`` by default.
 
 - Improved :doc:`readability-else-after-return
-  ` check now supports a 
+  ` check now supports a
   `WarnOnConditionVariables` option to control whether to refactor condition
   variables where possible.
 
 - Improved :doc:`readability-identifier-naming
   ` check.
 
-  Now able to rename member references in class template definitions with 
+  Now able to rename member references in class template definitions with
   explicit access.
 
 - Improved :doc:`readability-qualified-auto
Index: clang-tools-extra/clang-tidy/bugprone/NoEscapeCheck.h
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/bugprone/NoEscapeCheck.h
@@ -0,0 +1,39 @@
+//===--- NoEscapeCh

[PATCH] D82904: [clang-tidy] Warn pointer captured in async block

2020-07-07 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 276118.
ellis added a comment.

Update commit message


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82904/new/

https://reviews.llvm.org/D82904

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/NoEscapeCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/NoEscapeCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-no-escape.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-no-escape.m

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-no-escape.m
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-no-escape.m
@@ -0,0 +1,28 @@
+// RUN: %check_clang_tidy %s bugprone-no-escape %t
+// RUN: %check_clang_tidy %s -assume-filename=bugprone-no-escape.c bugprone-no-escape %t -- -- -fblocks
+
+typedef struct dispatch_queue_s *dispatch_queue_t;
+typedef struct dispatch_time_s *dispatch_time_t;
+typedef void (^dispatch_block_t)(void);
+void dispatch_async(dispatch_queue_t queue, dispatch_block_t block);
+void dispatch_after(dispatch_time_t when, dispatch_queue_t queue, dispatch_block_t block);
+
+extern dispatch_queue_t queue;
+
+void test_noescape_attribute(__attribute__((noescape)) int *p, int *q) {
+  dispatch_async(queue, ^{
+*p = 123;
+// CHECK-MESSAGES: :[[@LINE-2]]:25: warning: pointer 'p' with attribute 'noescape' is captured by an asynchronously-executed block [bugprone-no-escape]
+// CHECK-MESSAGES: :[[@LINE-4]]:30: note: the 'noescape' attribute is declared here.
+  });
+
+  dispatch_after(456, queue, ^{
+*p = 789;
+// CHECK-MESSAGES: :[[@LINE-2]]:30: warning: pointer 'p' with attribute 'noescape' is captured by an asynchronously-executed block [bugprone-no-escape]
+  });
+
+  dispatch_async(queue, ^{
+*q = 0;
+// CHECK-MESSAGES-NOT: :[[@LINE-2]]:25: warning: pointer 'q' with attribute 'noescape' is captured by an asynchronously-executed block
+  });
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -70,6 +70,7 @@
`bugprone-misplaced-widening-cast `_,
`bugprone-move-forwarding-reference `_, "Yes"
`bugprone-multiple-statement-macro `_,
+   `bugprone-no-escape `_, "Yes"
`bugprone-not-null-terminated-result `_, "Yes"
`bugprone-parent-virtual-call `_, "Yes"
`bugprone-posix-return `_, "Yes"
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone-no-escape.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone-no-escape.rst
@@ -0,0 +1,18 @@
+.. title:: clang-tidy - bugprone-no-escape
+
+bugprone-no-escape
+==
+
+Finds pointers with the ``noescape`` attribute that are captured by an
+asynchronously-executed block. The block arguments in ``dispatch_async()`` and
+``dispatch_after()`` are guaranteed to escape, so it is an error if a pointer with the
+``noescape`` attribute is captured by one of these blocks.
+
+The following is an example of an invalid use of the ``noescape`` attribute.
+
+  .. code-block:: objc
+void foo(__attribute__((noescape)) int *p) {
+  dispatch_async(queue, ^{
+*p = 123;
+  });
+});
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -94,6 +94,12 @@
   result of a memory allocation function (``malloc()``, ``calloc()``,
   ``realloc()``, ``alloca()``) instead of its argument.
 
+- New :doc:`bugprone-no-escape
+  ` check.
+
+  Finds pointers with the ``noescape`` attribute that are captured by an
+  asynchronously-executed block.
+
 - New :doc:`bugprone-spuriously-wake-up-functions
   ` check.
 
@@ -201,14 +207,14 @@
   Now checks ``std::basic_string_view`` by default.
 
 - Improved :doc:`readability-else-after-return
-  ` check now supports a 
+  ` check now supports a
   `WarnOnConditionVariables` option to control whether to refactor condition
   variables where possible.
 
 - Improved :doc:`readability-identifier-naming
   ` check.
 
-  Now able to rename member references in class template definitions with 
+  Now able to rename member references in class template definitions with
   explicit access.
 
 - Improved :doc:`readability-qualified-auto
Index: clang-tools-extra/clang-tidy/bugprone/NoEscapeCheck.h
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/bugprone/NoEscapeCheck.h
@@ -0,0 +1,39 @@
+//===--- NoEscapeCheck.

[PATCH] D82904: [clang-tidy] Warn pointer captured in async block

2020-07-07 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added a comment.

Hey @aaron.ballman, thanks for accepting my diff! Would you mind landing my 
diff since I don't have commit access yet?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82904/new/

https://reviews.llvm.org/D82904



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


[PATCH] D82904: [clang-tidy] Warn pointer captured in async block

2020-07-07 Thread Ellis Hoag via Phabricator via cfe-commits
ellis marked an inline comment as done.
ellis added inline comments.



Comment at: clang-tools-extra/docs/clang-tidy/checks/bugprone-no-escape.rst:13
+
+  .. code-block:: objc
+void foo(__attribute__((noescape)) int *p) {

It looks like I triggered a build failure for the clang-tools docs 
http://lab.llvm.org:8011/builders/clang-tools-sphinx-docs/builds/62418

I think the fix is to add a new line here, but I haven't been able to test it 
locally.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82904/new/

https://reviews.llvm.org/D82904



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


[PATCH] D82904: [clang-tidy] Warn pointer captured in async block

2020-06-30 Thread Ellis Hoag via Phabricator via cfe-commits
ellis created this revision.
Herald added subscribers: cfe-commits, xazax.hun, mgorny.
Herald added a project: clang.
ellis added a reviewer: clang-tools-extra.

The block arguments in `dispatch_async()` and `dispatch_after()` are
guaranteed to escape. If those blocks capture any pointers with the
`noescape` attribute then it is an error.

Test Plan:
ninja check-clang-tools


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82904

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/NoEscapeCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/NoEscapeCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-no-escape.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-no-escape.m

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-no-escape.m
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-no-escape.m
@@ -0,0 +1,27 @@
+// RUN: %check_clang_tidy %s bugprone-no-escape %t
+
+typedef struct dispatch_queue_s *dispatch_queue_t;
+typedef struct dispatch_time_s *dispatch_time_t;
+typedef void (^dispatch_block_t)(void);
+void dispatch_async(dispatch_queue_t queue, dispatch_block_t block);
+void dispatch_after(dispatch_time_t when, dispatch_queue_t queue, dispatch_block_t block);
+
+extern dispatch_queue_t queue;
+
+void test_noescape_attribute(__attribute__((noescape)) int *p, int *q) {
+  dispatch_async(queue, ^{
+*p = 123;
+// CHECK-MESSAGES: :[[@LINE-2]]:25: warning: Pointer 'p' with attribute 'noescape' is captured by an asynchronously-executed block [bugprone-no-escape]
+// CHECK-MESSAGES: :[[@LINE-4]]:30: note: The 'noescape' attribute is declared here.
+  });
+
+  dispatch_after(456, queue, ^{
+*p = 789;
+// CHECK-MESSAGES: :[[@LINE-2]]:30: warning: Pointer 'p' with attribute 'noescape' is captured by an asynchronously-executed block [bugprone-no-escape]
+  });
+
+  dispatch_async(queue, ^{
+*q = 0;
+// CHECK-MESSAGES-NOT: ::[@LINE-2]:{{[0-9]*}}: warning: {{.*}} [bugprone-no-escape]
+  });
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -70,6 +70,7 @@
`bugprone-misplaced-widening-cast `_,
`bugprone-move-forwarding-reference `_, "Yes"
`bugprone-multiple-statement-macro `_,
+   `bugprone-no-escape `_, "Yes"
`bugprone-not-null-terminated-result `_, "Yes"
`bugprone-parent-virtual-call `_, "Yes"
`bugprone-posix-return `_, "Yes"
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone-no-escape.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone-no-escape.rst
@@ -0,0 +1,18 @@
+.. title:: clang-tidy - bugprone-no-escape
+
+bugprone-no-escape
+==
+
+Finds pointers with the ``noescape`` attribute that are captured by an
+asynchronously-executed block. The block arguments in ``dispatch_async()`` and
+``dispatch_after()`` are guaranteed to escape, so it is an error if a pointer with the
+``noescape`` attribute is captured by one of these blocks.
+
+The following is an example of an invalid use of the ``noescape`` attribute.
+
+  .. code-block:: objc
+void foo(__attribute__((noescape)) int *p) {
+  dispatch_async(queue, ^{
+*p = 123;
+  });
+});
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -94,6 +94,12 @@
   result of a memory allocation function (``malloc()``, ``calloc()``,
   ``realloc()``, ``alloca()``) instead of its argument.
 
+- New :doc:`bugprone-no-escape
+  ` check.
+
+  Finds pointers with the `noescape` attribute that are captured by an
+  asynchronously-executed block.
+
 - New :doc:`bugprone-spuriously-wake-up-functions
   ` check.
 
Index: clang-tools-extra/clang-tidy/bugprone/NoEscapeCheck.h
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/bugprone/NoEscapeCheck.h
@@ -0,0 +1,36 @@
+//===--- NoEscapeCheck.h - clang-tidy ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NOESCAPECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NOESCAPECHECK_H
+
+#include ".

[PATCH] D82904: [clang-tidy] Warn pointer captured in async block

2020-06-30 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 274618.
ellis added a comment.

Applied changes suggested in comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82904/new/

https://reviews.llvm.org/D82904

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/NoEscapeCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/NoEscapeCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-no-escape.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-no-escape.m

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-no-escape.m
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-no-escape.m
@@ -0,0 +1,27 @@
+// RUN: %check_clang_tidy %s bugprone-no-escape %t
+
+typedef struct dispatch_queue_s *dispatch_queue_t;
+typedef struct dispatch_time_s *dispatch_time_t;
+typedef void (^dispatch_block_t)(void);
+void dispatch_async(dispatch_queue_t queue, dispatch_block_t block);
+void dispatch_after(dispatch_time_t when, dispatch_queue_t queue, dispatch_block_t block);
+
+extern dispatch_queue_t queue;
+
+void test_noescape_attribute(__attribute__((noescape)) int *p, int *q) {
+  dispatch_async(queue, ^{
+*p = 123;
+// CHECK-MESSAGES: :[[@LINE-2]]:25: warning: pointer 'p' with attribute 'noescape' is captured by an asynchronously-executed block [bugprone-no-escape]
+// CHECK-MESSAGES: :[[@LINE-4]]:30: note: the 'noescape' attribute is declared here.
+  });
+
+  dispatch_after(456, queue, ^{
+*p = 789;
+// CHECK-MESSAGES: :[[@LINE-2]]:30: warning: pointer 'p' with attribute 'noescape' is captured by an asynchronously-executed block [bugprone-no-escape]
+  });
+
+  dispatch_async(queue, ^{
+*q = 0;
+// CHECK-MESSAGES-NOT: :[[@LINE-2]]:25: warning: pointer 'q' with attribute 'noescape' is captured by an asynchronously-executed block
+  });
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -70,6 +70,7 @@
`bugprone-misplaced-widening-cast `_,
`bugprone-move-forwarding-reference `_, "Yes"
`bugprone-multiple-statement-macro `_,
+   `bugprone-no-escape `_, "Yes"
`bugprone-not-null-terminated-result `_, "Yes"
`bugprone-parent-virtual-call `_, "Yes"
`bugprone-posix-return `_, "Yes"
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone-no-escape.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone-no-escape.rst
@@ -0,0 +1,18 @@
+.. title:: clang-tidy - bugprone-no-escape
+
+bugprone-no-escape
+==
+
+Finds pointers with the ``noescape`` attribute that are captured by an
+asynchronously-executed block. The block arguments in ``dispatch_async()`` and
+``dispatch_after()`` are guaranteed to escape, so it is an error if a pointer with the
+``noescape`` attribute is captured by one of these blocks.
+
+The following is an example of an invalid use of the ``noescape`` attribute.
+
+  .. code-block:: objc
+void foo(__attribute__((noescape)) int *p) {
+  dispatch_async(queue, ^{
+*p = 123;
+  });
+});
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -94,6 +94,12 @@
   result of a memory allocation function (``malloc()``, ``calloc()``,
   ``realloc()``, ``alloca()``) instead of its argument.
 
+- New :doc:`bugprone-no-escape
+  ` check.
+
+  Finds pointers with the `noescape` attribute that are captured by an
+  asynchronously-executed block.
+
 - New :doc:`bugprone-spuriously-wake-up-functions
   ` check.
 
Index: clang-tools-extra/clang-tidy/bugprone/NoEscapeCheck.h
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/bugprone/NoEscapeCheck.h
@@ -0,0 +1,36 @@
+//===--- NoEscapeCheck.h - clang-tidy ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NOESCAPECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NOESCAPECHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace bugprone {
+
+/// Block arguments in `dispatch_async()` and `dispatch_after()` are g

[PATCH] D82904: [clang-tidy] Warn pointer captured in async block

2020-06-30 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 274622.
ellis added a comment.

Add double backtick to doc


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82904/new/

https://reviews.llvm.org/D82904

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/NoEscapeCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/NoEscapeCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-no-escape.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-no-escape.m

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-no-escape.m
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-no-escape.m
@@ -0,0 +1,27 @@
+// RUN: %check_clang_tidy %s bugprone-no-escape %t
+
+typedef struct dispatch_queue_s *dispatch_queue_t;
+typedef struct dispatch_time_s *dispatch_time_t;
+typedef void (^dispatch_block_t)(void);
+void dispatch_async(dispatch_queue_t queue, dispatch_block_t block);
+void dispatch_after(dispatch_time_t when, dispatch_queue_t queue, dispatch_block_t block);
+
+extern dispatch_queue_t queue;
+
+void test_noescape_attribute(__attribute__((noescape)) int *p, int *q) {
+  dispatch_async(queue, ^{
+*p = 123;
+// CHECK-MESSAGES: :[[@LINE-2]]:25: warning: pointer 'p' with attribute 'noescape' is captured by an asynchronously-executed block [bugprone-no-escape]
+// CHECK-MESSAGES: :[[@LINE-4]]:30: note: the 'noescape' attribute is declared here.
+  });
+
+  dispatch_after(456, queue, ^{
+*p = 789;
+// CHECK-MESSAGES: :[[@LINE-2]]:30: warning: pointer 'p' with attribute 'noescape' is captured by an asynchronously-executed block [bugprone-no-escape]
+  });
+
+  dispatch_async(queue, ^{
+*q = 0;
+// CHECK-MESSAGES-NOT: :[[@LINE-2]]:25: warning: pointer 'q' with attribute 'noescape' is captured by an asynchronously-executed block
+  });
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -70,6 +70,7 @@
`bugprone-misplaced-widening-cast `_,
`bugprone-move-forwarding-reference `_, "Yes"
`bugprone-multiple-statement-macro `_,
+   `bugprone-no-escape `_, "Yes"
`bugprone-not-null-terminated-result `_, "Yes"
`bugprone-parent-virtual-call `_, "Yes"
`bugprone-posix-return `_, "Yes"
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone-no-escape.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone-no-escape.rst
@@ -0,0 +1,18 @@
+.. title:: clang-tidy - bugprone-no-escape
+
+bugprone-no-escape
+==
+
+Finds pointers with the ``noescape`` attribute that are captured by an
+asynchronously-executed block. The block arguments in ``dispatch_async()`` and
+``dispatch_after()`` are guaranteed to escape, so it is an error if a pointer with the
+``noescape`` attribute is captured by one of these blocks.
+
+The following is an example of an invalid use of the ``noescape`` attribute.
+
+  .. code-block:: objc
+void foo(__attribute__((noescape)) int *p) {
+  dispatch_async(queue, ^{
+*p = 123;
+  });
+});
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -94,6 +94,12 @@
   result of a memory allocation function (``malloc()``, ``calloc()``,
   ``realloc()``, ``alloca()``) instead of its argument.
 
+- New :doc:`bugprone-no-escape
+  ` check.
+
+  Finds pointers with the ``noescape`` attribute that are captured by an
+  asynchronously-executed block.
+
 - New :doc:`bugprone-spuriously-wake-up-functions
   ` check.
 
@@ -201,14 +207,14 @@
   Now checks ``std::basic_string_view`` by default.
 
 - Improved :doc:`readability-else-after-return
-  ` check now supports a 
+  ` check now supports a
   `WarnOnConditionVariables` option to control whether to refactor condition
   variables where possible.
 
 - Improved :doc:`readability-identifier-naming
   ` check.
 
-  Now able to rename member references in class template definitions with 
+  Now able to rename member references in class template definitions with
   explicit access.
 
 - Improved :doc:`readability-qualified-auto
Index: clang-tools-extra/clang-tidy/bugprone/NoEscapeCheck.h
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/bugprone/NoEscapeCheck.h
@@ -0,0 +1,36 @@
+//===--- NoEscapeCheck.h - clang-tidy ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under th

[PATCH] D82904: [clang-tidy] Warn pointer captured in async block

2020-06-30 Thread Ellis Hoag via Phabricator via cfe-commits
ellis marked an inline comment as done.
ellis added inline comments.



Comment at: clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp:125
+CheckFactories.registerCheck(
+"bugprone-no-escape");
 CheckFactories.registerCheck(

Not sure if we want to lint this line because it was generated by 
`clang-tidy/add_new_check.py` and every other `registerCheck` line is formatted 
in the same way.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82904/new/

https://reviews.llvm.org/D82904



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


[PATCH] D125693: [DebugInfo] Support types, imports and static locals declared in a lexical block (3/5)

2022-07-05 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added inline comments.



Comment at: llvm/test/Instrumentation/InstrProfiling/debug-info-correlate.ll:23
   call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 
x i8]* @__profn_foo, i32 0, i32 0), i64 12345678, i32 2, i32 0)
-  ret void
+  ret void, !dbg !17
 }

I asked the same question in D113741, but why is this test changed?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D125693/new/

https://reviews.llvm.org/D125693

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


[PATCH] D125693: [DebugInfo] Support types, imports and static locals declared in a lexical block (3/5)

2022-07-06 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added inline comments.



Comment at: llvm/test/Instrumentation/InstrProfiling/debug-info-correlate.ll:23
   call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 
x i8]* @__profn_foo, i32 0, i32 0), i64 12345678, i32 2, i32 0)
-  ret void
+  ret void, !dbg !17
 }

krisb wrote:
> ellis wrote:
> > I asked the same question in D113741, but why is this test changed?
> Normally, we emit function-local entities iff a parent function has location 
> information. This is done the same way for local variables, labels, 
> parameters, imported entities, and, //now,// for static locals as well.
> Before this change static locals behaved more like global variables and get 
> emitted doesn't matter its parent function. This patch makes them handled 
> more like local variables.
> 
> I believe either the call or the 'ret' (or, likely, both) had had DILocation 
> attached originally, but it has been removed to simplify the test.
I just checked and the `llvm.instrprof.increment` intrinsic does not have debug 
info attached. I think you're right that I removed debug info from the `ret` 
instruction to simplify the test.

This is a special case where a global and its debug info is synthesized.
https://github.com/llvm/llvm-project/blob/23c2bedfd93cfacc62009425c464e659a34e92e6/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp#L976-L1001

So I don't understand why this added debug info is necessary. Does the test 
fail otherwise?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D125693/new/

https://reviews.llvm.org/D125693

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


[PATCH] D125693: [DebugInfo] Support types, imports and static locals declared in a lexical block (3/5)

2022-07-06 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added inline comments.



Comment at: llvm/test/Instrumentation/InstrProfiling/debug-info-correlate.ll:23
   call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 
x i8]* @__profn_foo, i32 0, i32 0), i64 12345678, i32 2, i32 0)
-  ret void
+  ret void, !dbg !17
 }

krisb wrote:
> ellis wrote:
> > krisb wrote:
> > > ellis wrote:
> > > > I asked the same question in D113741, but why is this test changed?
> > > Normally, we emit function-local entities iff a parent function has 
> > > location information. This is done the same way for local variables, 
> > > labels, parameters, imported entities, and, //now,// for static locals as 
> > > well.
> > > Before this change static locals behaved more like global variables and 
> > > get emitted doesn't matter its parent function. This patch makes them 
> > > handled more like local variables.
> > > 
> > > I believe either the call or the 'ret' (or, likely, both) had had 
> > > DILocation attached originally, but it has been removed to simplify the 
> > > test.
> > I just checked and the `llvm.instrprof.increment` intrinsic does not have 
> > debug info attached. I think you're right that I removed debug info from 
> > the `ret` instruction to simplify the test.
> > 
> > This is a special case where a global and its debug info is synthesized.
> > https://github.com/llvm/llvm-project/blob/23c2bedfd93cfacc62009425c464e659a34e92e6/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp#L976-L1001
> > 
> > So I don't understand why this added debug info is necessary. Does the test 
> > fail otherwise?
> Right, the test would fail w/o the added DILocation, because `__profc_foo` 
> variable (which is function-local 'global' technically) would not be emitted. 
> With this patch we emit function-local entities if and only if the parent 
> function has LexicalScope defined (see createAndAddScopeChildren() and its 
> call from constructSubprogramScopeDIE()), otherwise we skip emitting all 
> function's children (including function-local 'globals').
Got it, thanks for explaining!

I'm ok with this because `llvm.instrprof.increment` should probably be next to 
some instruction with debug info.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D125693/new/

https://reviews.llvm.org/D125693

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


[PATCH] D130807: [InstrProf] Add the omitprofile attribute

2022-07-29 Thread Ellis Hoag via Phabricator via cfe-commits
ellis created this revision.
Herald added subscribers: Enna1, wenlei, jdoerfert, hiraditya.
Herald added a project: All.
ellis edited the summary of this revision.
ellis added reviewers: phosek, davidxl.
ellis published this revision for review.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

As discussed in [0], this diff adds the `omitprofile` attribute to
prevent the function from being profiled while allowing profiled
functions to be inlined into it. The `noprofile` attribute remains
unchanged.

The `noprofile` attribute is used for functions where it is
dangerous to add instrumentation to while the `omitprofile` attribute is
used to reduce code size or performance overhead.

[0] 
https://discourse.llvm.org/t/why-does-the-noprofile-attribute-restrict-inlining/64108


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130807

Files:
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/CodeGenPGO.cpp
  clang/test/CodeGen/profile-function-groups.c
  llvm/docs/LangRef.rst
  llvm/include/llvm/Bitcode/LLVMBitCodes.h
  llvm/include/llvm/IR/Attributes.td
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
  llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
  llvm/lib/Transforms/Utils/CodeExtractor.cpp
  llvm/test/Bitcode/attributes.ll
  llvm/test/Transforms/GCOVProfiling/noprofile.ll
  llvm/test/Transforms/PGOProfile/noprofile.ll

Index: llvm/test/Transforms/PGOProfile/noprofile.ll
===
--- llvm/test/Transforms/PGOProfile/noprofile.ll
+++ llvm/test/Transforms/PGOProfile/noprofile.ll
@@ -21,4 +21,10 @@
   ret i32 %sub
 }
 
+define i32 @test3() omitprofile {
+entry:
+; CHECK-NOT: call void @llvm.instrprof.increment
+  ret i32 101
+}
+
 attributes #0 = { noprofile }
Index: llvm/test/Transforms/GCOVProfiling/noprofile.ll
===
--- llvm/test/Transforms/GCOVProfiling/noprofile.ll
+++ llvm/test/Transforms/GCOVProfiling/noprofile.ll
@@ -10,6 +10,14 @@
   ret i32 42, !dbg !27
 }
 
+; Test that the omitprofile attribute disables profiling.
+define dso_local i32 @omit_instr(i32 %a) omitprofile {
+; CHECK-LABEL: @omit_instr(
+; CHECK-NEXT:ret i32 52
+;
+  ret i32 52
+}
+
 define dso_local i32 @instr(i32 %a) !dbg !28 {
 ; CHECK-LABEL: @instr(
 ; CHECK-NEXT:[[GCOV_CTR:%.*]] = load i64, ptr @__llvm_gcov_ctr, align 4, !dbg [[DBG8:![0-9]+]]
Index: llvm/test/Bitcode/attributes.ll
===
--- llvm/test/Bitcode/attributes.ll
+++ llvm/test/Bitcode/attributes.ll
@@ -535,6 +535,9 @@
 ; CHECK: define void @f87() [[FNRETTHUNKEXTERN:#[0-9]+]]
 define void @f87() fn_ret_thunk_extern { ret void }
 
+; CHECK: define void @f88() [[OMITPROFILE:#[0-9]+]]
+define void @f88() omitprofile { ret void }
+
 ; CHECK: attributes #0 = { noreturn }
 ; CHECK: attributes #1 = { nounwind }
 ; CHECK: attributes #2 = { readnone }
@@ -589,4 +592,5 @@
 ; CHECK: attributes #51 = { uwtable(sync) }
 ; CHECK: attributes #52 = { nosanitize_bounds }
 ; CHECK: attributes [[FNRETTHUNKEXTERN]] = { fn_ret_thunk_extern }
+; CHECK: attributes [[OMITPROFILE]] = { omitprofile }
 ; CHECK: attributes #[[NOBUILTIN]] = { nobuiltin }
Index: llvm/lib/Transforms/Utils/CodeExtractor.cpp
===
--- llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -963,6 +963,7 @@
   case Attribute::NoCfCheck:
   case Attribute::MustProgress:
   case Attribute::NoProfile:
+  case Attribute::OmitProfile:
 break;
   // These attributes cannot be applied to functions.
   case Attribute::Alignment:
Index: llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
===
--- llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -1573,6 +1573,8 @@
   continue;
 if (F.hasFnAttribute(llvm::Attribute::NoProfile))
   continue;
+if (F.hasFnAttribute(llvm::Attribute::OmitProfile))
+  continue;
 auto &TLI = LookupTLI(F);
 auto *BPI = LookupBPI(F);
 auto *BFI = LookupBFI(F);
Index: llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
===
--- llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
+++ llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
@@ -797,6 +797,8 @@
   if (isUsingScopeBasedEH(F)) continue;
   if (F.hasFnAttribute(llvm::Attribute::NoProfile))
 continue;
+  if (F.hasFnAttribute(llvm::Attribute::OmitProfile))
+continue;
 
   // Add the function line number to the lines of the entry block
   // to have a counter for the function definition.
Index: ll

[PATCH] D130808: [InstrProf] Add new format for -fprofile-list=

2022-07-29 Thread Ellis Hoag via Phabricator via cfe-commits
ellis created this revision.
Herald added a project: All.
ellis edited the summary of this revision.
ellis added a reviewer: phosek.
ellis edited the summary of this revision.
ellis added a reviewer: davidxl.
ellis published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

In D130807  we added the `omitprofile` 
attribute. This commit
changes the format so we can either `forbid` or `omit` profiling
functions by adding the `noprofile` or `omitprofile` attributes,
respectively.

The behavior of the original format remains unchanged.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130808

Files:
  clang/docs/UsersManual.rst
  clang/include/clang/Basic/ProfileList.h
  clang/lib/Basic/ProfileList.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/test/CodeGen/profile-filter-new.c

Index: clang/test/CodeGen/profile-filter-new.c
===
--- /dev/null
+++ clang/test/CodeGen/profile-filter-new.c
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -fprofile-instrument=llvm -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|omitprofile)}}"
+
+// RUN: echo -e "[llvm]\nfunction:foo=omit" > %t0.list
+// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t0.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|omitprofile)}}" --check-prefixes=CHECK,OMIT-FOO
+
+// RUN: echo -e "[csllvm]\nfunction:bar=forbid" > %t1.list
+// RUN: %clang_cc1 -fprofile-instrument=csllvm -fprofile-list=%t1.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|omitprofile)}}" --check-prefixes=CHECK,FORBID-BAR
+// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t1.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|omitprofile)}}"
+
+// RUN: echo -e "[llvm]\ndefault:forbid\nfunction:foo=allow" > %t2.list
+// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t2.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|omitprofile)}}" --check-prefixes=CHECK,FORBID
+
+// RUN: echo -e "[llvm]\nsource:%s=forbid\nfunction:foo=allow" | sed -e 's/\\//g' > %t2.list
+// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t2.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|omitprofile)}}" --check-prefixes=CHECK,FORBID
+
+// OMIT-FOO: omitprofile
+// CHECK-LABEL: define {{.*}} @foo
+int foo(int a) { return 4 * a + 1; }
+
+// FORBID-BAR: noprofile
+// FORBID: noprofile
+// CHECK-LABEL: define {{.*}} @bar
+int bar(int a) { return 4 * a + 2; }
+
+// FORBID: noprofile
+// CHECK-LABEL: define {{.*}} @goo
+int goo(int a) { return 4 * a + 3; }
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1351,13 +1351,14 @@
 
   /// \returns true if \p Fn at \p Loc should be excluded from profile
   /// instrumentation by the SCL passed by \p -fprofile-list.
-  bool isFunctionBlockedByProfileList(llvm::Function *Fn,
-  SourceLocation Loc) const;
+  ProfileList::ExclusionType
+  isFunctionBlockedByProfileList(llvm::Function *Fn, SourceLocation Loc) const;
 
   /// \returns true if \p Fn at \p Loc should be excluded from profile
   /// instrumentation.
-  bool isFunctionBlockedFromProfileInstr(llvm::Function *Fn,
- SourceLocation Loc) const;
+  ProfileList::ExclusionType
+  isFunctionBlockedFromProfileInstr(llvm::Function *Fn,
+SourceLocation Loc) const;
 
   SanitizerMetadata *getSanitizerMetadata() {
 return SanitizerMD.get();
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -2890,46 +2890,44 @@
   return true;
 }
 
-bool CodeGenModule::isFunctionBlockedByProfileList(llvm::Function *Fn,
-   SourceLocation Loc) const {
+ProfileList::ExclusionType
+CodeGenModule::isFunctionBlockedByProfileList(llvm::Function *Fn,
+  SourceLocation Loc) const {
   const auto &ProfileList = getContext().getProfileList();
   // If the profile list is empty, then instrument everything.
   if (ProfileList.isEmpty())
-return false;
+return ProfileList::ALLOW;
   CodeGenOptions::ProfileInstrKind Kind = getCodeGenOpts().getProfileInstr();
   // First, check the function name.
-  Optional V = ProfileList.isFunctionExcluded(Fn->getName(), Kind);
-  if (V)
+  if (auto V = ProfileList.isFunctionExcluded(Fn->getName(), Kind))
 return *V;
   // Next, check the source location.
-  if (Loc.isValid()) {
-Optional

[PATCH] D130807: [InstrProf] Add the omitprofile attribute

2022-08-01 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added a comment.

In D130807#3688798 , @paulkirth wrote:

> Do you expect the difference between `noprofile` and `omitprofile` to be 
> confusing to users? I can certainly see how users could be confused by what 
> the difference is between `noprofile` and `omitprofile` ...
>
> Since what you want to communicate is "never profile"(which `noprofile` can 
> probably communicate as is) and "never profile this, but allow inlining of 
> profiled functions" (which I'm not sure `omitprofile` communicates), then 
> maybe there is a more obvious way we could communicate that? Maybe 
> `neverprofile` and `nodirectprofile` are more descriptive names? I don't love 
> the idea of changing an existing attribute name, but we can transparently 
> upgrade existing uses for backwards compatibility if we have to.  What do you 
> think?

I agree that `omitprofile` probably doesn't communicate the correct meaning 
very well. I like `nodirectprofile` because it hopefully implies that indirect 
profiles are allowed. I'm wondering if anyone else has suggestions.

Is there any precedent for renaming function attributes? My assumption was that 
users would add the `noprofile` attribute to source mostly for correctness 
concerns and `noprofile` is easy to remember and already in use, so I'd rather 
not change it.

> I also think this will need to need to be supported in LLVM's passes, right? 
> So the instrumentation passes in `PGOInstrumentation.cpp` (I can't remember 
> if 'InstrProfiling.cpp` will need this too), and probably the Inlining passes 
> too, right?  I assume those will be follow up patches, but I don't see them 
> in the current stack. Is that an accurate assumption?

I actually do have a change in `PGOInstrumentation.cpp` that skips profiling 
functions with this new attribute. As far as I know, this stack has all the 
necessary code changes.

> BTW I like the direction of these patches, I think adding the ability to 
> differentiate these cases will add a lot of value to the profiling runtimes + 
> coverage. :)

Thanks for the suggestion and feedback!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130807/new/

https://reviews.llvm.org/D130807

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


[PATCH] D130807: [InstrProf] Add the omitprofile attribute

2022-08-02 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 449463.
ellis added a comment.

Rename `omitprofile` => `skipprofile` since this seems slightly better to me. 
Of course I'm still open to more suggestions.

Also, fix the `profile-function-groups.c` test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130807/new/

https://reviews.llvm.org/D130807

Files:
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/CodeGenPGO.cpp
  clang/test/CodeGen/profile-function-groups.c
  llvm/docs/LangRef.rst
  llvm/include/llvm/Bitcode/LLVMBitCodes.h
  llvm/include/llvm/IR/Attributes.td
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
  llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
  llvm/lib/Transforms/Utils/CodeExtractor.cpp
  llvm/test/Bitcode/attributes.ll
  llvm/test/Transforms/GCOVProfiling/noprofile.ll
  llvm/test/Transforms/PGOProfile/noprofile.ll

Index: llvm/test/Transforms/PGOProfile/noprofile.ll
===
--- llvm/test/Transforms/PGOProfile/noprofile.ll
+++ llvm/test/Transforms/PGOProfile/noprofile.ll
@@ -21,4 +21,10 @@
   ret i32 %sub
 }
 
+define i32 @test3() skipprofile {
+entry:
+; CHECK-NOT: call void @llvm.instrprof.increment
+  ret i32 101
+}
+
 attributes #0 = { noprofile }
Index: llvm/test/Transforms/GCOVProfiling/noprofile.ll
===
--- llvm/test/Transforms/GCOVProfiling/noprofile.ll
+++ llvm/test/Transforms/GCOVProfiling/noprofile.ll
@@ -10,6 +10,14 @@
   ret i32 42, !dbg !27
 }
 
+; Test that the skipprofile attribute disables profiling.
+define dso_local i32 @skip_instr(i32 %a) skipprofile {
+; CHECK-LABEL: @skip_instr(
+; CHECK-NEXT:ret i32 52
+;
+  ret i32 52
+}
+
 define dso_local i32 @instr(i32 %a) !dbg !28 {
 ; CHECK-LABEL: @instr(
 ; CHECK-NEXT:[[GCOV_CTR:%.*]] = load i64, ptr @__llvm_gcov_ctr, align 4, !dbg [[DBG8:![0-9]+]]
Index: llvm/test/Bitcode/attributes.ll
===
--- llvm/test/Bitcode/attributes.ll
+++ llvm/test/Bitcode/attributes.ll
@@ -535,6 +535,9 @@
 ; CHECK: define void @f87() [[FNRETTHUNKEXTERN:#[0-9]+]]
 define void @f87() fn_ret_thunk_extern { ret void }
 
+; CHECK: define void @f88() [[SKIPPROFILE:#[0-9]+]]
+define void @f88() skipprofile { ret void }
+
 ; CHECK: attributes #0 = { noreturn }
 ; CHECK: attributes #1 = { nounwind }
 ; CHECK: attributes #2 = { readnone }
@@ -589,4 +592,5 @@
 ; CHECK: attributes #51 = { uwtable(sync) }
 ; CHECK: attributes #52 = { nosanitize_bounds }
 ; CHECK: attributes [[FNRETTHUNKEXTERN]] = { fn_ret_thunk_extern }
+; CHECK: attributes [[SKIPPROFILE]] = { skipprofile }
 ; CHECK: attributes #[[NOBUILTIN]] = { nobuiltin }
Index: llvm/lib/Transforms/Utils/CodeExtractor.cpp
===
--- llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -963,6 +963,7 @@
   case Attribute::NoCfCheck:
   case Attribute::MustProgress:
   case Attribute::NoProfile:
+  case Attribute::SkipProfile:
 break;
   // These attributes cannot be applied to functions.
   case Attribute::Alignment:
Index: llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
===
--- llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -1573,6 +1573,8 @@
   continue;
 if (F.hasFnAttribute(llvm::Attribute::NoProfile))
   continue;
+if (F.hasFnAttribute(llvm::Attribute::SkipProfile))
+  continue;
 auto &TLI = LookupTLI(F);
 auto *BPI = LookupBPI(F);
 auto *BFI = LookupBFI(F);
Index: llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
===
--- llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
+++ llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
@@ -797,6 +797,8 @@
   if (isUsingScopeBasedEH(F)) continue;
   if (F.hasFnAttribute(llvm::Attribute::NoProfile))
 continue;
+  if (F.hasFnAttribute(llvm::Attribute::SkipProfile))
+continue;
 
   // Add the function line number to the lines of the entry block
   // to have a counter for the function definition.
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -698,6 +698,8 @@
 return bitc::ATTR_KIND_NOCF_CHECK;
   case Attribute::NoProfile:
 return bitc::ATTR_KIND_NO_PROFILE;
+  case Attribute::SkipProfile:
+return bitc::ATTR_KIND_SKIP_PROFILE;
   case Attribute::NoUnwind:
 return bitc::ATTR_KIND_NO_UNWIND;
   case Attribute::NoSanitizeBounds:
Inde

[PATCH] D130808: [InstrProf] Add new format for -fprofile-list=

2022-08-02 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 449469.
ellis added a comment.

Rebase and rename `omitprofile` => `skipprofile`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130808/new/

https://reviews.llvm.org/D130808

Files:
  clang/docs/UsersManual.rst
  clang/include/clang/Basic/ProfileList.h
  clang/lib/Basic/ProfileList.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/test/CodeGen/profile-filter-new.c
  clang/test/CodeGen/profile-function-groups.c

Index: clang/test/CodeGen/profile-function-groups.c
===
--- clang/test/CodeGen/profile-function-groups.c
+++ clang/test/CodeGen/profile-function-groups.c
@@ -4,21 +4,21 @@
 
 // Group 0
 
-// SELECT1: noprofile
-// SELECT2: noprofile
+// SELECT1: skipprofile
+// SELECT2: skipprofile
 // CHECK: define {{.*}} @hoo()
 void hoo() {}
 
 // Group 1
-// SELECT0: noprofile
+// SELECT0: skipprofile
 
-// SELECT2: noprofile
+// SELECT2: skipprofile
 // CHECK: define {{.*}} @goo()
 void goo() {}
 
 // Group 2
-// SELECT0: noprofile
-// SELECT1: noprofile
+// SELECT0: skipprofile
+// SELECT1: skipprofile
 
 // CHECK: define {{.*}} @boo()
 void boo() {}
Index: clang/test/CodeGen/profile-filter-new.c
===
--- /dev/null
+++ clang/test/CodeGen/profile-filter-new.c
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -fprofile-instrument=llvm -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}"
+
+// RUN: echo -e "[llvm]\nfunction:foo=skip" > %t0.list
+// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t0.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}" --check-prefixes=CHECK,SKIP-FOO
+
+// RUN: echo -e "[csllvm]\nfunction:bar=forbid" > %t1.list
+// RUN: %clang_cc1 -fprofile-instrument=csllvm -fprofile-list=%t1.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}" --check-prefixes=CHECK,FORBID-BAR
+// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t1.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}"
+
+// RUN: echo -e "[llvm]\ndefault:forbid\nfunction:foo=allow" > %t2.list
+// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t2.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}" --check-prefixes=CHECK,FORBID
+
+// RUN: echo -e "[llvm]\nsource:%s=forbid\nfunction:foo=allow" | sed -e 's/\\//g' > %t2.list
+// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t2.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}" --check-prefixes=CHECK,FORBID
+
+// SKIP-FOO: skipprofile
+// CHECK-LABEL: define {{.*}} @foo
+int foo(int a) { return 4 * a + 1; }
+
+// FORBID-BAR: noprofile
+// FORBID: noprofile
+// CHECK-LABEL: define {{.*}} @bar
+int bar(int a) { return 4 * a + 2; }
+
+// FORBID: noprofile
+// CHECK-LABEL: define {{.*}} @goo
+int goo(int a) { return 4 * a + 3; }
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1351,13 +1351,14 @@
 
   /// \returns true if \p Fn at \p Loc should be excluded from profile
   /// instrumentation by the SCL passed by \p -fprofile-list.
-  bool isFunctionBlockedByProfileList(llvm::Function *Fn,
-  SourceLocation Loc) const;
+  ProfileList::ExclusionType
+  isFunctionBlockedByProfileList(llvm::Function *Fn, SourceLocation Loc) const;
 
   /// \returns true if \p Fn at \p Loc should be excluded from profile
   /// instrumentation.
-  bool isFunctionBlockedFromProfileInstr(llvm::Function *Fn,
- SourceLocation Loc) const;
+  ProfileList::ExclusionType
+  isFunctionBlockedFromProfileInstr(llvm::Function *Fn,
+SourceLocation Loc) const;
 
   SanitizerMetadata *getSanitizerMetadata() {
 return SanitizerMD.get();
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -2892,46 +2892,44 @@
   return true;
 }
 
-bool CodeGenModule::isFunctionBlockedByProfileList(llvm::Function *Fn,
-   SourceLocation Loc) const {
+ProfileList::ExclusionType
+CodeGenModule::isFunctionBlockedByProfileList(llvm::Function *Fn,
+  SourceLocation Loc) const {
   const auto &ProfileList = getContext().getProfileList();
   // If the profile list is empty, then instrument everything.
   if (ProfileList.isEmpty())
-return false;
+return ProfileList::ALLOW;
   CodeGenOptions::ProfileInstrK

[PATCH] D130808: [InstrProf] Add new format for -fprofile-list=

2022-08-04 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 449994.
ellis added a comment.

Fix case.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130808/new/

https://reviews.llvm.org/D130808

Files:
  clang/docs/UsersManual.rst
  clang/include/clang/Basic/ProfileList.h
  clang/lib/Basic/ProfileList.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/test/CodeGen/profile-filter-new.c
  clang/test/CodeGen/profile-function-groups.c

Index: clang/test/CodeGen/profile-function-groups.c
===
--- clang/test/CodeGen/profile-function-groups.c
+++ clang/test/CodeGen/profile-function-groups.c
@@ -4,21 +4,21 @@
 
 // Group 0
 
-// SELECT1: noprofile
-// SELECT2: noprofile
+// SELECT1: skipprofile
+// SELECT2: skipprofile
 // CHECK: define {{.*}} @hoo()
 void hoo() {}
 
 // Group 1
-// SELECT0: noprofile
+// SELECT0: skipprofile
 
-// SELECT2: noprofile
+// SELECT2: skipprofile
 // CHECK: define {{.*}} @goo()
 void goo() {}
 
 // Group 2
-// SELECT0: noprofile
-// SELECT1: noprofile
+// SELECT0: skipprofile
+// SELECT1: skipprofile
 
 // CHECK: define {{.*}} @boo()
 void boo() {}
Index: clang/test/CodeGen/profile-filter-new.c
===
--- /dev/null
+++ clang/test/CodeGen/profile-filter-new.c
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -fprofile-instrument=llvm -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}"
+
+// RUN: echo -e "[llvm]\nfunction:foo=skip" > %t0.list
+// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t0.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}" --check-prefixes=CHECK,SKIP-FOO
+
+// RUN: echo -e "[csllvm]\nfunction:bar=forbid" > %t1.list
+// RUN: %clang_cc1 -fprofile-instrument=csllvm -fprofile-list=%t1.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}" --check-prefixes=CHECK,FORBID-BAR
+// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t1.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}"
+
+// RUN: echo -e "[llvm]\ndefault:forbid\nfunction:foo=allow" > %t2.list
+// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t2.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}" --check-prefixes=CHECK,FORBID
+
+// RUN: echo -e "[llvm]\nsource:%s=forbid\nfunction:foo=allow" | sed -e 's/\\//g' > %t2.list
+// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t2.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}" --check-prefixes=CHECK,FORBID
+
+// SKIP-FOO: skipprofile
+// CHECK-LABEL: define {{.*}} @foo
+int foo(int a) { return 4 * a + 1; }
+
+// FORBID-BAR: noprofile
+// FORBID: noprofile
+// CHECK-LABEL: define {{.*}} @bar
+int bar(int a) { return 4 * a + 2; }
+
+// FORBID: noprofile
+// CHECK-LABEL: define {{.*}} @goo
+int goo(int a) { return 4 * a + 3; }
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1351,13 +1351,14 @@
 
   /// \returns true if \p Fn at \p Loc should be excluded from profile
   /// instrumentation by the SCL passed by \p -fprofile-list.
-  bool isFunctionBlockedByProfileList(llvm::Function *Fn,
-  SourceLocation Loc) const;
+  ProfileList::ExclusionType
+  isFunctionBlockedByProfileList(llvm::Function *Fn, SourceLocation Loc) const;
 
   /// \returns true if \p Fn at \p Loc should be excluded from profile
   /// instrumentation.
-  bool isFunctionBlockedFromProfileInstr(llvm::Function *Fn,
- SourceLocation Loc) const;
+  ProfileList::ExclusionType
+  isFunctionBlockedFromProfileInstr(llvm::Function *Fn,
+SourceLocation Loc) const;
 
   SanitizerMetadata *getSanitizerMetadata() {
 return SanitizerMD.get();
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -2895,46 +2895,44 @@
   return true;
 }
 
-bool CodeGenModule::isFunctionBlockedByProfileList(llvm::Function *Fn,
-   SourceLocation Loc) const {
+ProfileList::ExclusionType
+CodeGenModule::isFunctionBlockedByProfileList(llvm::Function *Fn,
+  SourceLocation Loc) const {
   const auto &ProfileList = getContext().getProfileList();
   // If the profile list is empty, then instrument everything.
   if (ProfileList.isEmpty())
-return false;
+return ProfileList::Allow;
   CodeGenOptions::ProfileInstrKind Kind = getCodeGenOpts().getProfileIn

[PATCH] D130807: [InstrProf] Add the skipprofile attribute

2022-08-04 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 449995.
ellis added a comment.

Rebase and update docs


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130807/new/

https://reviews.llvm.org/D130807

Files:
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/CodeGenPGO.cpp
  clang/test/CodeGen/profile-function-groups.c
  llvm/docs/LangRef.rst
  llvm/include/llvm/Bitcode/LLVMBitCodes.h
  llvm/include/llvm/IR/Attributes.td
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
  llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
  llvm/lib/Transforms/Utils/CodeExtractor.cpp
  llvm/test/Bitcode/attributes.ll
  llvm/test/Transforms/GCOVProfiling/noprofile.ll
  llvm/test/Transforms/PGOProfile/noprofile.ll

Index: llvm/test/Transforms/PGOProfile/noprofile.ll
===
--- llvm/test/Transforms/PGOProfile/noprofile.ll
+++ llvm/test/Transforms/PGOProfile/noprofile.ll
@@ -21,4 +21,10 @@
   ret i32 %sub
 }
 
+define i32 @test3() skipprofile {
+entry:
+; CHECK-NOT: call void @llvm.instrprof.increment
+  ret i32 101
+}
+
 attributes #0 = { noprofile }
Index: llvm/test/Transforms/GCOVProfiling/noprofile.ll
===
--- llvm/test/Transforms/GCOVProfiling/noprofile.ll
+++ llvm/test/Transforms/GCOVProfiling/noprofile.ll
@@ -10,6 +10,14 @@
   ret i32 42, !dbg !27
 }
 
+; Test that the skipprofile attribute disables profiling.
+define dso_local i32 @skip_instr(i32 %a) skipprofile {
+; CHECK-LABEL: @skip_instr(
+; CHECK-NEXT:ret i32 52
+;
+  ret i32 52
+}
+
 define dso_local i32 @instr(i32 %a) !dbg !28 {
 ; CHECK-LABEL: @instr(
 ; CHECK-NEXT:[[GCOV_CTR:%.*]] = load i64, ptr @__llvm_gcov_ctr, align 4, !dbg [[DBG8:![0-9]+]]
Index: llvm/test/Bitcode/attributes.ll
===
--- llvm/test/Bitcode/attributes.ll
+++ llvm/test/Bitcode/attributes.ll
@@ -535,6 +535,9 @@
 ; CHECK: define void @f87() [[FNRETTHUNKEXTERN:#[0-9]+]]
 define void @f87() fn_ret_thunk_extern { ret void }
 
+; CHECK: define void @f88() [[SKIPPROFILE:#[0-9]+]]
+define void @f88() skipprofile { ret void }
+
 ; CHECK: attributes #0 = { noreturn }
 ; CHECK: attributes #1 = { nounwind }
 ; CHECK: attributes #2 = { readnone }
@@ -589,4 +592,5 @@
 ; CHECK: attributes #51 = { uwtable(sync) }
 ; CHECK: attributes #52 = { nosanitize_bounds }
 ; CHECK: attributes [[FNRETTHUNKEXTERN]] = { fn_ret_thunk_extern }
+; CHECK: attributes [[SKIPPROFILE]] = { skipprofile }
 ; CHECK: attributes #[[NOBUILTIN]] = { nobuiltin }
Index: llvm/lib/Transforms/Utils/CodeExtractor.cpp
===
--- llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -963,6 +963,7 @@
   case Attribute::NoCfCheck:
   case Attribute::MustProgress:
   case Attribute::NoProfile:
+  case Attribute::SkipProfile:
 break;
   // These attributes cannot be applied to functions.
   case Attribute::Alignment:
Index: llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
===
--- llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -1574,6 +1574,8 @@
   continue;
 if (F.hasFnAttribute(llvm::Attribute::NoProfile))
   continue;
+if (F.hasFnAttribute(llvm::Attribute::SkipProfile))
+  continue;
 auto &TLI = LookupTLI(F);
 auto *BPI = LookupBPI(F);
 auto *BFI = LookupBFI(F);
Index: llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
===
--- llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
+++ llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
@@ -797,6 +797,8 @@
   if (isUsingScopeBasedEH(F)) continue;
   if (F.hasFnAttribute(llvm::Attribute::NoProfile))
 continue;
+  if (F.hasFnAttribute(llvm::Attribute::SkipProfile))
+continue;
 
   // Add the function line number to the lines of the entry block
   // to have a counter for the function definition.
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -698,6 +698,8 @@
 return bitc::ATTR_KIND_NOCF_CHECK;
   case Attribute::NoProfile:
 return bitc::ATTR_KIND_NO_PROFILE;
+  case Attribute::SkipProfile:
+return bitc::ATTR_KIND_SKIP_PROFILE;
   case Attribute::NoUnwind:
 return bitc::ATTR_KIND_NO_UNWIND;
   case Attribute::NoSanitizeBounds:
Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
===
--- llvm/lib/Bitcode/Reader/BitcodeRea

[PATCH] D130807: [InstrProf] Add the skipprofile attribute

2022-08-04 Thread Ellis Hoag via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG12e78ff88105: [InstrProf] Add the skipprofile attribute 
(authored by ellis).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130807/new/

https://reviews.llvm.org/D130807

Files:
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/CodeGenPGO.cpp
  clang/test/CodeGen/profile-function-groups.c
  llvm/docs/LangRef.rst
  llvm/include/llvm/Bitcode/LLVMBitCodes.h
  llvm/include/llvm/IR/Attributes.td
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
  llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
  llvm/lib/Transforms/Utils/CodeExtractor.cpp
  llvm/test/Bitcode/attributes.ll
  llvm/test/Transforms/GCOVProfiling/noprofile.ll
  llvm/test/Transforms/PGOProfile/noprofile.ll

Index: llvm/test/Transforms/PGOProfile/noprofile.ll
===
--- llvm/test/Transforms/PGOProfile/noprofile.ll
+++ llvm/test/Transforms/PGOProfile/noprofile.ll
@@ -21,4 +21,10 @@
   ret i32 %sub
 }
 
+define i32 @test3() skipprofile {
+entry:
+; CHECK-NOT: call void @llvm.instrprof.increment
+  ret i32 101
+}
+
 attributes #0 = { noprofile }
Index: llvm/test/Transforms/GCOVProfiling/noprofile.ll
===
--- llvm/test/Transforms/GCOVProfiling/noprofile.ll
+++ llvm/test/Transforms/GCOVProfiling/noprofile.ll
@@ -10,6 +10,14 @@
   ret i32 42, !dbg !27
 }
 
+; Test that the skipprofile attribute disables profiling.
+define dso_local i32 @skip_instr(i32 %a) skipprofile {
+; CHECK-LABEL: @skip_instr(
+; CHECK-NEXT:ret i32 52
+;
+  ret i32 52
+}
+
 define dso_local i32 @instr(i32 %a) !dbg !28 {
 ; CHECK-LABEL: @instr(
 ; CHECK-NEXT:[[GCOV_CTR:%.*]] = load i64, ptr @__llvm_gcov_ctr, align 4, !dbg [[DBG8:![0-9]+]]
Index: llvm/test/Bitcode/attributes.ll
===
--- llvm/test/Bitcode/attributes.ll
+++ llvm/test/Bitcode/attributes.ll
@@ -535,6 +535,9 @@
 ; CHECK: define void @f87() [[FNRETTHUNKEXTERN:#[0-9]+]]
 define void @f87() fn_ret_thunk_extern { ret void }
 
+; CHECK: define void @f88() [[SKIPPROFILE:#[0-9]+]]
+define void @f88() skipprofile { ret void }
+
 ; CHECK: attributes #0 = { noreturn }
 ; CHECK: attributes #1 = { nounwind }
 ; CHECK: attributes #2 = { readnone }
@@ -589,4 +592,5 @@
 ; CHECK: attributes #51 = { uwtable(sync) }
 ; CHECK: attributes #52 = { nosanitize_bounds }
 ; CHECK: attributes [[FNRETTHUNKEXTERN]] = { fn_ret_thunk_extern }
+; CHECK: attributes [[SKIPPROFILE]] = { skipprofile }
 ; CHECK: attributes #[[NOBUILTIN]] = { nobuiltin }
Index: llvm/lib/Transforms/Utils/CodeExtractor.cpp
===
--- llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -963,6 +963,7 @@
   case Attribute::NoCfCheck:
   case Attribute::MustProgress:
   case Attribute::NoProfile:
+  case Attribute::SkipProfile:
 break;
   // These attributes cannot be applied to functions.
   case Attribute::Alignment:
Index: llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
===
--- llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -1574,6 +1574,8 @@
   continue;
 if (F.hasFnAttribute(llvm::Attribute::NoProfile))
   continue;
+if (F.hasFnAttribute(llvm::Attribute::SkipProfile))
+  continue;
 auto &TLI = LookupTLI(F);
 auto *BPI = LookupBPI(F);
 auto *BFI = LookupBFI(F);
Index: llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
===
--- llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
+++ llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
@@ -797,6 +797,8 @@
   if (isUsingScopeBasedEH(F)) continue;
   if (F.hasFnAttribute(llvm::Attribute::NoProfile))
 continue;
+  if (F.hasFnAttribute(llvm::Attribute::SkipProfile))
+continue;
 
   // Add the function line number to the lines of the entry block
   // to have a counter for the function definition.
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -698,6 +698,8 @@
 return bitc::ATTR_KIND_NOCF_CHECK;
   case Attribute::NoProfile:
 return bitc::ATTR_KIND_NO_PROFILE;
+  case Attribute::SkipProfile:
+return bitc::ATTR_KIND_SKIP_PROFILE;
   case Attribute::NoUnwind:
 return bitc::ATTR_KIND_NO_UNWIND;
   case Attribute::NoSanitizeBounds:
Index: llvm/lib/Bitc

[PATCH] D130808: [InstrProf] Add new format for -fprofile-list=

2022-08-04 Thread Ellis Hoag via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb692312ca432: [InstrProf] Add new format for -fprofile-list= 
(authored by ellis).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130808/new/

https://reviews.llvm.org/D130808

Files:
  clang/docs/UsersManual.rst
  clang/include/clang/Basic/ProfileList.h
  clang/lib/Basic/ProfileList.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/test/CodeGen/profile-filter-new.c
  clang/test/CodeGen/profile-function-groups.c

Index: clang/test/CodeGen/profile-function-groups.c
===
--- clang/test/CodeGen/profile-function-groups.c
+++ clang/test/CodeGen/profile-function-groups.c
@@ -4,21 +4,21 @@
 
 // Group 0
 
-// SELECT1: noprofile
-// SELECT2: noprofile
+// SELECT1: skipprofile
+// SELECT2: skipprofile
 // CHECK: define {{.*}} @hoo()
 void hoo() {}
 
 // Group 1
-// SELECT0: noprofile
+// SELECT0: skipprofile
 
-// SELECT2: noprofile
+// SELECT2: skipprofile
 // CHECK: define {{.*}} @goo()
 void goo() {}
 
 // Group 2
-// SELECT0: noprofile
-// SELECT1: noprofile
+// SELECT0: skipprofile
+// SELECT1: skipprofile
 
 // CHECK: define {{.*}} @boo()
 void boo() {}
Index: clang/test/CodeGen/profile-filter-new.c
===
--- /dev/null
+++ clang/test/CodeGen/profile-filter-new.c
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -fprofile-instrument=llvm -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}"
+
+// RUN: echo -e "[llvm]\nfunction:foo=skip" > %t0.list
+// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t0.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}" --check-prefixes=CHECK,SKIP-FOO
+
+// RUN: echo -e "[csllvm]\nfunction:bar=forbid" > %t1.list
+// RUN: %clang_cc1 -fprofile-instrument=csllvm -fprofile-list=%t1.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}" --check-prefixes=CHECK,FORBID-BAR
+// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t1.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}"
+
+// RUN: echo -e "[llvm]\ndefault:forbid\nfunction:foo=allow" > %t2.list
+// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t2.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}" --check-prefixes=CHECK,FORBID
+
+// RUN: echo -e "[llvm]\nsource:%s=forbid\nfunction:foo=allow" | sed -e 's/\\//g' > %t2.list
+// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t2.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}" --check-prefixes=CHECK,FORBID
+
+// SKIP-FOO: skipprofile
+// CHECK-LABEL: define {{.*}} @foo
+int foo(int a) { return 4 * a + 1; }
+
+// FORBID-BAR: noprofile
+// FORBID: noprofile
+// CHECK-LABEL: define {{.*}} @bar
+int bar(int a) { return 4 * a + 2; }
+
+// FORBID: noprofile
+// CHECK-LABEL: define {{.*}} @goo
+int goo(int a) { return 4 * a + 3; }
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1351,13 +1351,14 @@
 
   /// \returns true if \p Fn at \p Loc should be excluded from profile
   /// instrumentation by the SCL passed by \p -fprofile-list.
-  bool isFunctionBlockedByProfileList(llvm::Function *Fn,
-  SourceLocation Loc) const;
+  ProfileList::ExclusionType
+  isFunctionBlockedByProfileList(llvm::Function *Fn, SourceLocation Loc) const;
 
   /// \returns true if \p Fn at \p Loc should be excluded from profile
   /// instrumentation.
-  bool isFunctionBlockedFromProfileInstr(llvm::Function *Fn,
- SourceLocation Loc) const;
+  ProfileList::ExclusionType
+  isFunctionBlockedFromProfileInstr(llvm::Function *Fn,
+SourceLocation Loc) const;
 
   SanitizerMetadata *getSanitizerMetadata() {
 return SanitizerMD.get();
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -2895,46 +2895,44 @@
   return true;
 }
 
-bool CodeGenModule::isFunctionBlockedByProfileList(llvm::Function *Fn,
-   SourceLocation Loc) const {
+ProfileList::ExclusionType
+CodeGenModule::isFunctionBlockedByProfileList(llvm::Function *Fn,
+  SourceLocation Loc) const {
   const auto &ProfileList = getContext().getProfileList();
   // If the profile list is empty, then instrument everything.

[PATCH] D130808: [InstrProf] Add new format for -fprofile-list=

2022-08-04 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added a comment.

In D130808#3700074 , @thakis wrote:

> Reverted in 0eb7d86f5873ce897894339a3cc5bc69ca507bee 
>  for now.

Thanks for reverting. I'm looking into it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130808/new/

https://reviews.llvm.org/D130808

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


[PATCH] D131195: [InstrProf][attempt 2] Add new format for -fprofile-list=

2022-08-04 Thread Ellis Hoag via Phabricator via cfe-commits
ellis created this revision.
Herald added a project: All.
ellis added reviewers: phosek, davidxl, thakis.
ellis published this revision for review.
ellis added inline comments.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.



Comment at: clang/test/CodeGen/profile-filter-new.c:14
+// RUN: echo "[llvm]" > %t2.list
+// RUN: echo "source:%s=forbid" | sed -e 's/\\//g' >> %t2.list
+// RUN: echo "function:foo=allow" >> %t2.list

I think the Windows test from D130808 broke because this `sed` command was 
interacting badly with newlines. Using multiple `echo` commands seems to work.


In D130807  we added the `skipprofile` 
attribute. This commit
changes the format so we can either `forbid` or `skip` profiling
functions by adding the `noprofile` or `skipprofile` attributes,
respectively. The behavior of the original format remains
unchanged.

Also, add the `skipprofile` attribute when using
`-fprofile-function-groups`.

This was originally landed as https://reviews.llvm.org/D130808 but was
reverted due to a Windows test failure.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131195

Files:
  clang/docs/UsersManual.rst
  clang/include/clang/Basic/ProfileList.h
  clang/lib/Basic/ProfileList.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/test/CodeGen/profile-filter-new.c
  clang/test/CodeGen/profile-function-groups.c

Index: clang/test/CodeGen/profile-function-groups.c
===
--- clang/test/CodeGen/profile-function-groups.c
+++ clang/test/CodeGen/profile-function-groups.c
@@ -4,21 +4,21 @@
 
 // Group 0
 
-// SELECT1: noprofile
-// SELECT2: noprofile
+// SELECT1: skipprofile
+// SELECT2: skipprofile
 // CHECK: define {{.*}} @hoo()
 void hoo() {}
 
 // Group 1
-// SELECT0: noprofile
+// SELECT0: skipprofile
 
-// SELECT2: noprofile
+// SELECT2: skipprofile
 // CHECK: define {{.*}} @goo()
 void goo() {}
 
 // Group 2
-// SELECT0: noprofile
-// SELECT1: noprofile
+// SELECT0: skipprofile
+// SELECT1: skipprofile
 
 // CHECK: define {{.*}} @boo()
 void boo() {}
Index: clang/test/CodeGen/profile-filter-new.c
===
--- /dev/null
+++ clang/test/CodeGen/profile-filter-new.c
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -fprofile-instrument=llvm -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}"
+
+// RUN: echo -e "[llvm]\nfunction:foo=skip" > %t0.list
+// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t0.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}" --check-prefixes=CHECK,SKIP-FOO
+
+// RUN: echo -e "[csllvm]\nfunction:bar=forbid" > %t1.list
+// RUN: %clang_cc1 -fprofile-instrument=csllvm -fprofile-list=%t1.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}" --check-prefixes=CHECK,FORBID-BAR
+// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t1.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}"
+
+// RUN: echo -e "[llvm]\ndefault:forbid\nfunction:foo=allow" > %t2.list
+// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t2.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}" --check-prefixes=CHECK,FORBID
+
+// RUN: echo "[llvm]" > %t2.list
+// RUN: echo "source:%s=forbid" | sed -e 's/\\//g' >> %t2.list
+// RUN: echo "function:foo=allow" >> %t2.list
+// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t2.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}" --check-prefixes=CHECK,FORBID
+
+// SKIP-FOO: skipprofile
+// CHECK-LABEL: define {{.*}} @foo
+int foo(int a) { return 4 * a + 1; }
+
+// FORBID-BAR: noprofile
+// FORBID: noprofile
+// CHECK-LABEL: define {{.*}} @bar
+int bar(int a) { return 4 * a + 2; }
+
+// FORBID: noprofile
+// CHECK-LABEL: define {{.*}} @goo
+int goo(int a) { return 4 * a + 3; }
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1351,13 +1351,14 @@
 
   /// \returns true if \p Fn at \p Loc should be excluded from profile
   /// instrumentation by the SCL passed by \p -fprofile-list.
-  bool isFunctionBlockedByProfileList(llvm::Function *Fn,
-  SourceLocation Loc) const;
+  ProfileList::ExclusionType
+  isFunctionBlockedByProfileList(llvm::Function *Fn, SourceLocation Loc) const;
 
   /// \returns true if \p Fn at \p Loc should be excluded from profile
   /// instrumentation.
-  bool isFunctionBlockedFromProfileInstr(llvm::Function *Fn,
- SourceLocation Loc) const;
+  ProfileList::ExclusionTyp

[PATCH] D131195: [InstrProf][attempt 2] Add new format for -fprofile-list=

2022-08-04 Thread Ellis Hoag via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6f4c3c0f6463: [InstrProf][attempt 2] Add new format for 
-fprofile-list= (authored by ellis).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131195/new/

https://reviews.llvm.org/D131195

Files:
  clang/docs/UsersManual.rst
  clang/include/clang/Basic/ProfileList.h
  clang/lib/Basic/ProfileList.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/test/CodeGen/profile-filter-new.c
  clang/test/CodeGen/profile-function-groups.c

Index: clang/test/CodeGen/profile-function-groups.c
===
--- clang/test/CodeGen/profile-function-groups.c
+++ clang/test/CodeGen/profile-function-groups.c
@@ -4,21 +4,21 @@
 
 // Group 0
 
-// SELECT1: noprofile
-// SELECT2: noprofile
+// SELECT1: skipprofile
+// SELECT2: skipprofile
 // CHECK: define {{.*}} @hoo()
 void hoo() {}
 
 // Group 1
-// SELECT0: noprofile
+// SELECT0: skipprofile
 
-// SELECT2: noprofile
+// SELECT2: skipprofile
 // CHECK: define {{.*}} @goo()
 void goo() {}
 
 // Group 2
-// SELECT0: noprofile
-// SELECT1: noprofile
+// SELECT0: skipprofile
+// SELECT1: skipprofile
 
 // CHECK: define {{.*}} @boo()
 void boo() {}
Index: clang/test/CodeGen/profile-filter-new.c
===
--- /dev/null
+++ clang/test/CodeGen/profile-filter-new.c
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -fprofile-instrument=llvm -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}"
+
+// RUN: echo -e "[llvm]\nfunction:foo=skip" > %t0.list
+// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t0.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}" --check-prefixes=CHECK,SKIP-FOO
+
+// RUN: echo -e "[csllvm]\nfunction:bar=forbid" > %t1.list
+// RUN: %clang_cc1 -fprofile-instrument=csllvm -fprofile-list=%t1.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}" --check-prefixes=CHECK,FORBID-BAR
+// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t1.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}"
+
+// RUN: echo -e "[llvm]\ndefault:forbid\nfunction:foo=allow" > %t2.list
+// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t2.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}" --check-prefixes=CHECK,FORBID
+
+// RUN: echo "[llvm]" > %t2.list
+// RUN: echo "source:%s=forbid" | sed -e 's/\\//g' >> %t2.list
+// RUN: echo "function:foo=allow" >> %t2.list
+// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t2.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}" --check-prefixes=CHECK,FORBID
+
+// SKIP-FOO: skipprofile
+// CHECK-LABEL: define {{.*}} @foo
+int foo(int a) { return 4 * a + 1; }
+
+// FORBID-BAR: noprofile
+// FORBID: noprofile
+// CHECK-LABEL: define {{.*}} @bar
+int bar(int a) { return 4 * a + 2; }
+
+// FORBID: noprofile
+// CHECK-LABEL: define {{.*}} @goo
+int goo(int a) { return 4 * a + 3; }
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1351,13 +1351,14 @@
 
   /// \returns true if \p Fn at \p Loc should be excluded from profile
   /// instrumentation by the SCL passed by \p -fprofile-list.
-  bool isFunctionBlockedByProfileList(llvm::Function *Fn,
-  SourceLocation Loc) const;
+  ProfileList::ExclusionType
+  isFunctionBlockedByProfileList(llvm::Function *Fn, SourceLocation Loc) const;
 
   /// \returns true if \p Fn at \p Loc should be excluded from profile
   /// instrumentation.
-  bool isFunctionBlockedFromProfileInstr(llvm::Function *Fn,
- SourceLocation Loc) const;
+  ProfileList::ExclusionType
+  isFunctionBlockedFromProfileInstr(llvm::Function *Fn,
+SourceLocation Loc) const;
 
   SanitizerMetadata *getSanitizerMetadata() {
 return SanitizerMD.get();
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -2895,46 +2895,44 @@
   return true;
 }
 
-bool CodeGenModule::isFunctionBlockedByProfileList(llvm::Function *Fn,
-   SourceLocation Loc) const {
+ProfileList::ExclusionType
+CodeGenModule::isFunctionBlockedByProfileList(llvm::Function *Fn,
+  SourceLocation Loc) const {
   const auto &ProfileList = getCon

[PATCH] D107024: [DIBuilder] Do not replace empty enum types

2021-07-28 Thread Ellis Hoag via Phabricator via cfe-commits
ellis created this revision.
ellis added a reviewer: aprantl.
Herald added subscribers: dexonsmith, lxfind, hiraditya.
ellis requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

It looks like this array was missed in 4276d4a8d08b7640eb57cabf6988a5cf65b228b6

Fixed tests that expected `elements` to be empty or depeneded on the order of 
the empty DINode.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107024

Files:
  clang/test/CodeGen/debug-info-codeview-heapallocsite.c
  clang/test/CodeGen/debug-info-macro.c
  clang/test/CodeGenCXX/debug-info-codeview-var-templates.cpp
  clang/test/CodeGenCXX/debug-info-cxx1y.cpp
  clang/test/CodeGenCXX/debug-info-template.cpp
  clang/test/CodeGenCXX/debug-info-var-template-partial-spec.cpp
  clang/test/CodeGenCoroutines/coro-dwarf.cpp
  llvm/lib/IR/DIBuilder.cpp
  llvm/test/CodeGen/AArch64/GlobalISel/constant-mir-debugify.mir
  llvm/test/CodeGen/AArch64/GlobalISel/phi-mir-debugify.mir
  llvm/test/DebugInfo/debugify.ll

Index: llvm/test/DebugInfo/debugify.ll
===
--- llvm/test/DebugInfo/debugify.ll
+++ llvm/test/DebugInfo/debugify.ll
@@ -61,7 +61,7 @@
 ; CHECK-DAG: !llvm.debugify = !{![[NUM_INSTS:.*]], ![[NUM_VARS:.*]]}
 ; CHECK-DAG: "Debug Info Version"
 
-; CHECK-DAG: ![[CU]] = distinct !DICompileUnit(language: DW_LANG_C, file: {{.*}}, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: {{.*}})
+; CHECK-DAG: ![[CU]] = distinct !DICompileUnit(language: DW_LANG_C, file: {{.*}}, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
 ; CHECK-DAG: !DIFile(filename: "", directory: "/")
 ; CHECK-DAG: distinct !DISubprogram(name: "foo", linkageName: "foo", scope: null, file: {{.*}}, line: 1, type: {{.*}}, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: {{.*}}, retainedNodes: {{.*}})
 ; CHECK-DAG: distinct !DISubprogram(name: "bar", linkageName: "bar", scope: null, file: {{.*}}, line: 2, type: {{.*}}, scopeLine: 2, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: {{.*}}, retainedNodes: {{.*}})
Index: llvm/test/CodeGen/AArch64/GlobalISel/phi-mir-debugify.mir
===
--- llvm/test/CodeGen/AArch64/GlobalISel/phi-mir-debugify.mir
+++ llvm/test/CodeGen/AArch64/GlobalISel/phi-mir-debugify.mir
@@ -38,39 +38,39 @@
   ; CHECK:   liveins: $w0
   ; CHECK:   [[COPY:%[0-9]+]]:_(s32) = COPY $w0, debug-location !11
   ; CHECK:   DBG_VALUE [[COPY]](s32), $noreg, !9, !DIExpression(), debug-location !11
-  ; CHECK:   [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0, debug-location !DILocation(line: 2, column: 1, scope: !6)
-  ; CHECK:   DBG_VALUE [[C]](s32), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 2, column: 1, scope: !6)
-  ; CHECK:   [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 1, debug-location !DILocation(line: 3, column: 1, scope: !6)
-  ; CHECK:   DBG_VALUE [[C1]](s32), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 3, column: 1, scope: !6)
-  ; CHECK:   [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 2, debug-location !DILocation(line: 4, column: 1, scope: !6)
-  ; CHECK:   DBG_VALUE [[C2]](s32), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 4, column: 1, scope: !6)
-  ; CHECK:   [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(ugt), [[COPY]](s32), [[C]], debug-location !DILocation(line: 5, column: 1, scope: !6)
-  ; CHECK:   DBG_VALUE [[ICMP]](s1), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 5, column: 1, scope: !6)
-  ; CHECK:   G_BRCOND [[ICMP]](s1), %bb.1, debug-location !DILocation(line: 6, column: 1, scope: !6)
-  ; CHECK:   G_BR %bb.2, debug-location !DILocation(line: 7, column: 1, scope: !6)
+  ; CHECK:   [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0, debug-location !DILocation(line: 2, column: 1, scope: !5)
+  ; CHECK:   DBG_VALUE [[C]](s32), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 2, column: 1, scope: !5)
+  ; CHECK:   [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 1, debug-location !DILocation(line: 3, column: 1, scope: !5)
+  ; CHECK:   DBG_VALUE [[C1]](s32), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 3, column: 1, scope: !5)
+  ; CHECK:   [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 2, debug-location !DILocation(line: 4, column: 1, scope: !5)
+  ; CHECK:   DBG_VALUE [[C2]](s32), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 4, column: 1, scope: !5)
+  ; CHECK:   [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(ugt), [[COPY]](s32), [[C]], debug-location !DILocation(line: 5, column: 1, scope: !5)
+  ; CHECK:   DBG_VALUE [[ICMP]](s1), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 5, column: 1, scope: !5)
+  ; CHECK:   G_BRCOND [[ICMP]](s1), %bb.1, debug-location !DILocation(line: 6, column: 1, scope: !5)
+  ; CHECK:   G_BR %bb.2, debug-location !DILocation(line: 7, column: 1, scope: !5)
   ; 

[PATCH] D107024: [DIBuilder] Do not replace empty enum types

2021-07-28 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 362614.
ellis added a comment.

Remove whitespace changes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107024/new/

https://reviews.llvm.org/D107024

Files:
  clang/test/CodeGen/debug-info-codeview-heapallocsite.c
  clang/test/CodeGen/debug-info-macro.c
  clang/test/CodeGenCXX/debug-info-codeview-var-templates.cpp
  clang/test/CodeGenCXX/debug-info-cxx1y.cpp
  clang/test/CodeGenCXX/debug-info-template.cpp
  clang/test/CodeGenCXX/debug-info-var-template-partial-spec.cpp
  clang/test/CodeGenCoroutines/coro-dwarf.cpp
  llvm/lib/IR/DIBuilder.cpp
  llvm/test/CodeGen/AArch64/GlobalISel/constant-mir-debugify.mir
  llvm/test/CodeGen/AArch64/GlobalISel/phi-mir-debugify.mir
  llvm/test/DebugInfo/debugify.ll

Index: llvm/test/DebugInfo/debugify.ll
===
--- llvm/test/DebugInfo/debugify.ll
+++ llvm/test/DebugInfo/debugify.ll
@@ -61,7 +61,7 @@
 ; CHECK-DAG: !llvm.debugify = !{![[NUM_INSTS:.*]], ![[NUM_VARS:.*]]}
 ; CHECK-DAG: "Debug Info Version"
 
-; CHECK-DAG: ![[CU]] = distinct !DICompileUnit(language: DW_LANG_C, file: {{.*}}, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: {{.*}})
+; CHECK-DAG: ![[CU]] = distinct !DICompileUnit(language: DW_LANG_C, file: {{.*}}, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
 ; CHECK-DAG: !DIFile(filename: "", directory: "/")
 ; CHECK-DAG: distinct !DISubprogram(name: "foo", linkageName: "foo", scope: null, file: {{.*}}, line: 1, type: {{.*}}, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: {{.*}}, retainedNodes: {{.*}})
 ; CHECK-DAG: distinct !DISubprogram(name: "bar", linkageName: "bar", scope: null, file: {{.*}}, line: 2, type: {{.*}}, scopeLine: 2, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: {{.*}}, retainedNodes: {{.*}})
Index: llvm/test/CodeGen/AArch64/GlobalISel/phi-mir-debugify.mir
===
--- llvm/test/CodeGen/AArch64/GlobalISel/phi-mir-debugify.mir
+++ llvm/test/CodeGen/AArch64/GlobalISel/phi-mir-debugify.mir
@@ -38,39 +38,39 @@
   ; CHECK:   liveins: $w0
   ; CHECK:   [[COPY:%[0-9]+]]:_(s32) = COPY $w0, debug-location !11
   ; CHECK:   DBG_VALUE [[COPY]](s32), $noreg, !9, !DIExpression(), debug-location !11
-  ; CHECK:   [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0, debug-location !DILocation(line: 2, column: 1, scope: !6)
-  ; CHECK:   DBG_VALUE [[C]](s32), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 2, column: 1, scope: !6)
-  ; CHECK:   [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 1, debug-location !DILocation(line: 3, column: 1, scope: !6)
-  ; CHECK:   DBG_VALUE [[C1]](s32), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 3, column: 1, scope: !6)
-  ; CHECK:   [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 2, debug-location !DILocation(line: 4, column: 1, scope: !6)
-  ; CHECK:   DBG_VALUE [[C2]](s32), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 4, column: 1, scope: !6)
-  ; CHECK:   [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(ugt), [[COPY]](s32), [[C]], debug-location !DILocation(line: 5, column: 1, scope: !6)
-  ; CHECK:   DBG_VALUE [[ICMP]](s1), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 5, column: 1, scope: !6)
-  ; CHECK:   G_BRCOND [[ICMP]](s1), %bb.1, debug-location !DILocation(line: 6, column: 1, scope: !6)
-  ; CHECK:   G_BR %bb.2, debug-location !DILocation(line: 7, column: 1, scope: !6)
+  ; CHECK:   [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0, debug-location !DILocation(line: 2, column: 1, scope: !5)
+  ; CHECK:   DBG_VALUE [[C]](s32), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 2, column: 1, scope: !5)
+  ; CHECK:   [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 1, debug-location !DILocation(line: 3, column: 1, scope: !5)
+  ; CHECK:   DBG_VALUE [[C1]](s32), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 3, column: 1, scope: !5)
+  ; CHECK:   [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 2, debug-location !DILocation(line: 4, column: 1, scope: !5)
+  ; CHECK:   DBG_VALUE [[C2]](s32), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 4, column: 1, scope: !5)
+  ; CHECK:   [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(ugt), [[COPY]](s32), [[C]], debug-location !DILocation(line: 5, column: 1, scope: !5)
+  ; CHECK:   DBG_VALUE [[ICMP]](s1), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 5, column: 1, scope: !5)
+  ; CHECK:   G_BRCOND [[ICMP]](s1), %bb.1, debug-location !DILocation(line: 6, column: 1, scope: !5)
+  ; CHECK:   G_BR %bb.2, debug-location !DILocation(line: 7, column: 1, scope: !5)
   ; CHECK: bb.1:
   ; CHECK:   successors: %bb.3(0x8000)
-  ; CHECK:   [[ADD:%[0-9]+]]:_(s32) = G_ADD [[COPY]], [[C1]], debug-location !DILocation(line: 8, column: 1, scope: !6)
-  ; CHECK:   DBG_VALUE [[ADD]](s32), $noreg, !9, !DIExpression(), debug-location !DILoca

[PATCH] D107024: [DIBuilder] Do not replace empty enum types

2021-07-28 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 362637.
ellis added a comment.

Fix broken coro test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107024/new/

https://reviews.llvm.org/D107024

Files:
  clang/test/CodeGen/debug-info-codeview-heapallocsite.c
  clang/test/CodeGen/debug-info-macro.c
  clang/test/CodeGenCXX/debug-info-codeview-var-templates.cpp
  clang/test/CodeGenCXX/debug-info-cxx1y.cpp
  clang/test/CodeGenCXX/debug-info-template.cpp
  clang/test/CodeGenCXX/debug-info-var-template-partial-spec.cpp
  clang/test/CodeGenCoroutines/coro-dwarf.cpp
  llvm/lib/IR/DIBuilder.cpp
  llvm/test/CodeGen/AArch64/GlobalISel/constant-mir-debugify.mir
  llvm/test/CodeGen/AArch64/GlobalISel/phi-mir-debugify.mir
  llvm/test/DebugInfo/debugify.ll

Index: llvm/test/DebugInfo/debugify.ll
===
--- llvm/test/DebugInfo/debugify.ll
+++ llvm/test/DebugInfo/debugify.ll
@@ -61,7 +61,7 @@
 ; CHECK-DAG: !llvm.debugify = !{![[NUM_INSTS:.*]], ![[NUM_VARS:.*]]}
 ; CHECK-DAG: "Debug Info Version"
 
-; CHECK-DAG: ![[CU]] = distinct !DICompileUnit(language: DW_LANG_C, file: {{.*}}, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: {{.*}})
+; CHECK-DAG: ![[CU]] = distinct !DICompileUnit(language: DW_LANG_C, file: {{.*}}, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
 ; CHECK-DAG: !DIFile(filename: "", directory: "/")
 ; CHECK-DAG: distinct !DISubprogram(name: "foo", linkageName: "foo", scope: null, file: {{.*}}, line: 1, type: {{.*}}, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: {{.*}}, retainedNodes: {{.*}})
 ; CHECK-DAG: distinct !DISubprogram(name: "bar", linkageName: "bar", scope: null, file: {{.*}}, line: 2, type: {{.*}}, scopeLine: 2, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: {{.*}}, retainedNodes: {{.*}})
Index: llvm/test/CodeGen/AArch64/GlobalISel/phi-mir-debugify.mir
===
--- llvm/test/CodeGen/AArch64/GlobalISel/phi-mir-debugify.mir
+++ llvm/test/CodeGen/AArch64/GlobalISel/phi-mir-debugify.mir
@@ -38,39 +38,39 @@
   ; CHECK:   liveins: $w0
   ; CHECK:   [[COPY:%[0-9]+]]:_(s32) = COPY $w0, debug-location !11
   ; CHECK:   DBG_VALUE [[COPY]](s32), $noreg, !9, !DIExpression(), debug-location !11
-  ; CHECK:   [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0, debug-location !DILocation(line: 2, column: 1, scope: !6)
-  ; CHECK:   DBG_VALUE [[C]](s32), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 2, column: 1, scope: !6)
-  ; CHECK:   [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 1, debug-location !DILocation(line: 3, column: 1, scope: !6)
-  ; CHECK:   DBG_VALUE [[C1]](s32), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 3, column: 1, scope: !6)
-  ; CHECK:   [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 2, debug-location !DILocation(line: 4, column: 1, scope: !6)
-  ; CHECK:   DBG_VALUE [[C2]](s32), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 4, column: 1, scope: !6)
-  ; CHECK:   [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(ugt), [[COPY]](s32), [[C]], debug-location !DILocation(line: 5, column: 1, scope: !6)
-  ; CHECK:   DBG_VALUE [[ICMP]](s1), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 5, column: 1, scope: !6)
-  ; CHECK:   G_BRCOND [[ICMP]](s1), %bb.1, debug-location !DILocation(line: 6, column: 1, scope: !6)
-  ; CHECK:   G_BR %bb.2, debug-location !DILocation(line: 7, column: 1, scope: !6)
+  ; CHECK:   [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0, debug-location !DILocation(line: 2, column: 1, scope: !5)
+  ; CHECK:   DBG_VALUE [[C]](s32), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 2, column: 1, scope: !5)
+  ; CHECK:   [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 1, debug-location !DILocation(line: 3, column: 1, scope: !5)
+  ; CHECK:   DBG_VALUE [[C1]](s32), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 3, column: 1, scope: !5)
+  ; CHECK:   [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 2, debug-location !DILocation(line: 4, column: 1, scope: !5)
+  ; CHECK:   DBG_VALUE [[C2]](s32), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 4, column: 1, scope: !5)
+  ; CHECK:   [[ICMP:%[0-9]+]]:_(s1) = G_ICMP intpred(ugt), [[COPY]](s32), [[C]], debug-location !DILocation(line: 5, column: 1, scope: !5)
+  ; CHECK:   DBG_VALUE [[ICMP]](s1), $noreg, !9, !DIExpression(), debug-location !DILocation(line: 5, column: 1, scope: !5)
+  ; CHECK:   G_BRCOND [[ICMP]](s1), %bb.1, debug-location !DILocation(line: 6, column: 1, scope: !5)
+  ; CHECK:   G_BR %bb.2, debug-location !DILocation(line: 7, column: 1, scope: !5)
   ; CHECK: bb.1:
   ; CHECK:   successors: %bb.3(0x8000)
-  ; CHECK:   [[ADD:%[0-9]+]]:_(s32) = G_ADD [[COPY]], [[C1]], debug-location !DILocation(line: 8, column: 1, scope: !6)
-  ; CHECK:   DBG_VALUE [[ADD]](s32), $noreg, !9, !DIExpression(), debug-location !DILocation(

[PATCH] D129413: [InstrProf] Allow compiler generated functions in SCL

2022-07-11 Thread Ellis Hoag via Phabricator via cfe-commits
ellis created this revision.
Herald added a project: All.
ellis retitled this revision from "[instrprof] Allow compiler generated 
functions in SCL" to "[InstrProf] Allow compiler generated functions in SCL".
ellis edited the summary of this revision.
ellis added reviewers: kyulee, phosek.
ellis published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Allow compiler generated functions like `__clang_call_terminate` to be
blocked in the special case list (SCL) passed by the `-fprofile-list=` option.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129413

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/profile-filter-compiler-generated.cpp


Index: clang/test/CodeGen/profile-filter-compiler-generated.cpp
===
--- /dev/null
+++ clang/test/CodeGen/profile-filter-compiler-generated.cpp
@@ -0,0 +1,9 @@
+// RUN: echo "!fun:__clang_call_terminate" > %t.list
+// RUN: %clang -fprofile-generate -fprofile-list=%t.list -Wno-exceptions 
-emit-llvm -S %s -o - | FileCheck %s
+
+// CHECK-NOT: noprofile
+// CHECK-LABEL: define {{.*}} i32 @_Z3foov()
+int foo() noexcept { throw 0; }
+
+// CHECK: noprofile
+// CHECK-LABEL: define {{.*}} void @__clang_call_terminate(
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -3891,6 +3891,10 @@
 F->addFnAttrs(B);
   }
 
+  if (getCodeGenOpts().getProfileInstr() != CodeGenOptions::ProfileNone)
+if (isProfileInstrExcluded(F, SourceLocation()))
+  F->addFnAttr(llvm::Attribute::NoProfile);
+
   if (!DontDefer) {
 // All MSVC dtors other than the base dtor are linkonce_odr and delegate to
 // each other bottoming out with the base dtor.  Therefore we emit non-base


Index: clang/test/CodeGen/profile-filter-compiler-generated.cpp
===
--- /dev/null
+++ clang/test/CodeGen/profile-filter-compiler-generated.cpp
@@ -0,0 +1,9 @@
+// RUN: echo "!fun:__clang_call_terminate" > %t.list
+// RUN: %clang -fprofile-generate -fprofile-list=%t.list -Wno-exceptions -emit-llvm -S %s -o - | FileCheck %s
+
+// CHECK-NOT: noprofile
+// CHECK-LABEL: define {{.*}} i32 @_Z3foov()
+int foo() noexcept { throw 0; }
+
+// CHECK: noprofile
+// CHECK-LABEL: define {{.*}} void @__clang_call_terminate(
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -3891,6 +3891,10 @@
 F->addFnAttrs(B);
   }
 
+  if (getCodeGenOpts().getProfileInstr() != CodeGenOptions::ProfileNone)
+if (isProfileInstrExcluded(F, SourceLocation()))
+  F->addFnAttr(llvm::Attribute::NoProfile);
+
   if (!DontDefer) {
 // All MSVC dtors other than the base dtor are linkonce_odr and delegate to
 // each other bottoming out with the base dtor.  Therefore we emit non-base
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129413: [InstrProf] Allow compiler generated functions in SCL

2022-07-11 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added inline comments.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:3894-3896
+  if (getCodeGenOpts().getProfileInstr() != CodeGenOptions::ProfileNone)
+if (isProfileInstrExcluded(F, SourceLocation()))
+  F->addFnAttr(llvm::Attribute::NoProfile);

phosek wrote:
> Do we still need 
> https://github.com/llvm/llvm-project/blob/759e5e0096f650515799805828f9ac5b7d4a7303/clang/lib/CodeGen/CodeGenFunction.cpp#L856
>  if we set the attribute here?
Both are needed. Here the attribute is added in `GetOrCreateLLVMFunction()` 
which I believe only creates compiler generated functions. Where you linked is 
called when normal functions are generated.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129413/new/

https://reviews.llvm.org/D129413

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


[PATCH] D129413: [InstrProf] Allow compiler generated functions in SCL

2022-07-11 Thread Ellis Hoag via Phabricator via cfe-commits
ellis planned changes to this revision.
ellis added inline comments.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:3894-3896
+  if (getCodeGenOpts().getProfileInstr() != CodeGenOptions::ProfileNone)
+if (isProfileInstrExcluded(F, SourceLocation()))
+  F->addFnAttr(llvm::Attribute::NoProfile);

ellis wrote:
> phosek wrote:
> > Do we still need 
> > https://github.com/llvm/llvm-project/blob/759e5e0096f650515799805828f9ac5b7d4a7303/clang/lib/CodeGen/CodeGenFunction.cpp#L856
> >  if we set the attribute here?
> Both are needed. Here the attribute is added in `GetOrCreateLLVMFunction()` 
> which I believe only creates compiler generated functions. Where you linked 
> is called when normal functions are generated.
Oh sorry, I was mistaken. I'd like to figure out how to only have this code in 
one location.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129413/new/

https://reviews.llvm.org/D129413

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


[PATCH] D129413: [InstrProf] Allow compiler generated functions in SCL

2022-07-12 Thread Ellis Hoag via Phabricator via cfe-commits
ellis abandoned this revision.
ellis added a comment.

The function `__clang_call_terminate` seems to be a special case that clang 
builds itself. This diff might be too much for this rare specific case. Closing.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129413/new/

https://reviews.llvm.org/D129413

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


[PATCH] D129594: [InstrProf] Add options to profile function groups

2022-07-13 Thread Ellis Hoag via Phabricator via cfe-commits
ellis created this revision.
Herald added a subscriber: Enna1.
Herald added a project: All.
ellis edited the summary of this revision.
ellis added reviewers: ianlevesque, kyulee, MaskRay, phosek, wenlei, davidxl.
Herald added a subscriber: StephenFan.
ellis updated this revision to Diff 444091.
ellis added a comment.
ellis edited the summary of this revision.
ellis updated this revision to Diff 444108.
ellis edited the summary of this revision.
ellis published this revision for review.
Herald added projects: clang, Sanitizers.
Herald added subscribers: Sanitizers, cfe-commits.

Add docs


ellis added a comment.

Fix test


Add two options, `-fprofile-function-groups=N` and 
`-fprofile-selected-function-group=i` used to partition functions into `N` 
groups and only instrument the functions in group `i`. Similar options were 
added to xray in https://reviews.llvm.org/D87953 and the goal is the same; to 
reduce instrumented size overhead by spreading the overhead across multiple 
builds. Raw profiles from different groups can be added like normal using the 
`llvm-profdata merge` command.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129594

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/docs/UsersManual.rst
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/profile-function-groups.c
  compiler-rt/test/profile/instrprof-groups.c

Index: compiler-rt/test/profile/instrprof-groups.c
===
--- /dev/null
+++ compiler-rt/test/profile/instrprof-groups.c
@@ -0,0 +1,28 @@
+// RUN: %clang_pgogen -fprofile-function-groups=3 -fprofile-selected-function-group=0 %s -o %t.0.out
+// RUN: %clang_pgogen -fprofile-function-groups=3 -fprofile-selected-function-group=1 %s -o %t.1.out
+// RUN: %clang_pgogen -fprofile-function-groups=3 -fprofile-selected-function-group=2 %s -o %t.2.out
+// RUN: env LLVM_PROFILE_FILE=%t.0.profraw %run %t.0.out
+// RUN: env LLVM_PROFILE_FILE=%t.1.profraw %run %t.1.out
+// RUN: env LLVM_PROFILE_FILE=%t.2.profraw %run %t.2.out
+// RUN: llvm-profdata merge -o %t.profdata %t.*.profraw
+// RUN: llvm-profdata show %t.profdata --all-functions | FileCheck %s
+
+int foo(int i) { return 4 * i + 1; }
+int bar(int i) { return 4 * i + 2; }
+int goo(int i) { return 4 * i + 3; }
+
+int main(int argc, char *argv[]) {
+  foo(5);
+  bar(6);
+  goo(7);
+  return 0;
+}
+
+// Even though we ran this code three times, we expect all counts to be one if
+// functions were partitioned into groups correctly.
+
+// CHECK: Counters: 1
+// CHECK: Counters: 1
+// CHECK: Counters: 1
+// CHECK: Counters: 1
+// CHECK: Total functions: 4
Index: clang/test/CodeGen/profile-function-groups.c
===
--- /dev/null
+++ clang/test/CodeGen/profile-function-groups.c
@@ -0,0 +1,24 @@
+// RUN: %clang -fprofile-generate -fprofile-function-groups=3 -fprofile-selected-function-group=0 -emit-llvm -S %s -o - | FileCheck %s --check-prefixes=CHECK,SELECT0
+// RUN: %clang -fprofile-generate -fprofile-function-groups=3 -fprofile-selected-function-group=1 -emit-llvm -S %s -o - | FileCheck %s --check-prefixes=CHECK,SELECT1
+// RUN: %clang -fprofile-generate -fprofile-function-groups=3 -fprofile-selected-function-group=2 -emit-llvm -S %s -o - | FileCheck %s --check-prefixes=CHECK,SELECT2
+
+// Group 0
+// SELECT0-NOT: noprofile
+// SELECT1: noprofile
+// SELECT2: noprofile
+// CHECK: define {{.*}} @goo()
+void goo() {}
+
+// Group 1
+// SELECT0: noprofile
+// SELECT1-NOT: noprofile
+// SELECT2: noprofile
+// CHECK: define {{.*}} @boo()
+void boo() {}
+
+// Group 2
+// SELECT0: noprofile
+// SELECT1: noprofile
+// SELECT2-NOT: noprofile
+// CHECK: define {{.*}} @foo()
+void foo() {}
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -982,6 +982,27 @@
 CmdArgs.push_back("-fprofile-update=atomic");
   }
 
+  int FunctionGroups = 1;
+  int SelectedFunctionGroup = 0;
+  if (const auto *A = Args.getLastArg(options::OPT_fprofile_function_groups)) {
+StringRef Val = A->getValue();
+if (Val.getAsInteger(0, FunctionGroups) || FunctionGroups < 1)
+  D.Diag(diag::err_drv_invalid_int_value) << A->getAsString(Args) << Val;
+  }
+  if (const auto *A =
+  Args.getLastArg(options::OPT_fprofile_selected_function_group)) {
+StringRef Val = A->getValue();
+if (Val.getAsInteger(0, SelectedFunctionGroup) ||
+SelectedFunctionGroup < 0 || SelectedFunctionGroup >= FunctionGroups)
+  D.Diag(diag::err_drv_invalid_int_value) << A->getAsString(Args) << Val;
+  }
+  if (FunctionGroups != 1)
+CmdArgs.push_back(Args.MakeArgString("-fpro

[PATCH] D129594: [InstrProf] Add options to profile function groups

2022-07-13 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added inline comments.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:2871
+  if (NumGroups > 1) {
+auto Group = llvm::MD5Hash(Fn->getName()) % NumGroups;
+if (Group != getCodeGenOpts().ProfileSelectedFunctionGroup)

ianlevesque wrote:
> In D87953 I used crc32 to avoid computing an md5 hash on every function name.
I see, I'll change that. Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129594/new/

https://reviews.llvm.org/D129594

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


[PATCH] D129594: [InstrProf] Add options to profile function groups

2022-07-13 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 444327.
ellis added a comment.

Use `crc32` rather than `md5` to compute function hashes faster.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129594/new/

https://reviews.llvm.org/D129594

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/docs/UsersManual.rst
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/profile-function-groups.c
  compiler-rt/test/profile/instrprof-groups.c

Index: compiler-rt/test/profile/instrprof-groups.c
===
--- /dev/null
+++ compiler-rt/test/profile/instrprof-groups.c
@@ -0,0 +1,28 @@
+// RUN: %clang_pgogen -fprofile-function-groups=3 -fprofile-selected-function-group=0 %s -o %t.0.out
+// RUN: %clang_pgogen -fprofile-function-groups=3 -fprofile-selected-function-group=1 %s -o %t.1.out
+// RUN: %clang_pgogen -fprofile-function-groups=3 -fprofile-selected-function-group=2 %s -o %t.2.out
+// RUN: env LLVM_PROFILE_FILE=%t.0.profraw %run %t.0.out
+// RUN: env LLVM_PROFILE_FILE=%t.1.profraw %run %t.1.out
+// RUN: env LLVM_PROFILE_FILE=%t.2.profraw %run %t.2.out
+// RUN: llvm-profdata merge -o %t.profdata %t.*.profraw
+// RUN: llvm-profdata show %t.profdata --all-functions | FileCheck %s
+
+int foo(int i) { return 4 * i + 1; }
+int bar(int i) { return 4 * i + 2; }
+int goo(int i) { return 4 * i + 3; }
+
+int main(int argc, char *argv[]) {
+  foo(5);
+  bar(6);
+  goo(7);
+  return 0;
+}
+
+// Even though we ran this code three times, we expect all counts to be one if
+// functions were partitioned into groups correctly.
+
+// CHECK: Counters: 1
+// CHECK: Counters: 1
+// CHECK: Counters: 1
+// CHECK: Counters: 1
+// CHECK: Total functions: 4
Index: clang/test/CodeGen/profile-function-groups.c
===
--- /dev/null
+++ clang/test/CodeGen/profile-function-groups.c
@@ -0,0 +1,24 @@
+// RUN: %clang -fprofile-generate -fprofile-function-groups=3 -fprofile-selected-function-group=0 -emit-llvm -S %s -o - | FileCheck %s --check-prefixes=CHECK,SELECT0
+// RUN: %clang -fprofile-generate -fprofile-function-groups=3 -fprofile-selected-function-group=1 -emit-llvm -S %s -o - | FileCheck %s --check-prefixes=CHECK,SELECT1
+// RUN: %clang -fprofile-generate -fprofile-function-groups=3 -fprofile-selected-function-group=2 -emit-llvm -S %s -o - | FileCheck %s --check-prefixes=CHECK,SELECT2
+
+// Group 0
+// SELECT0-NOT: noprofile
+// SELECT1: noprofile
+// SELECT2: noprofile
+// CHECK: define {{.*}} @hoo()
+void hoo() {}
+
+// Group 1
+// SELECT0: noprofile
+// SELECT1-NOT: noprofile
+// SELECT2: noprofile
+// CHECK: define {{.*}} @goo()
+void goo() {}
+
+// Group 2
+// SELECT0: noprofile
+// SELECT1: noprofile
+// SELECT2-NOT: noprofile
+// CHECK: define {{.*}} @boo()
+void boo() {}
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -982,6 +982,27 @@
 CmdArgs.push_back("-fprofile-update=atomic");
   }
 
+  int FunctionGroups = 1;
+  int SelectedFunctionGroup = 0;
+  if (const auto *A = Args.getLastArg(options::OPT_fprofile_function_groups)) {
+StringRef Val = A->getValue();
+if (Val.getAsInteger(0, FunctionGroups) || FunctionGroups < 1)
+  D.Diag(diag::err_drv_invalid_int_value) << A->getAsString(Args) << Val;
+  }
+  if (const auto *A =
+  Args.getLastArg(options::OPT_fprofile_selected_function_group)) {
+StringRef Val = A->getValue();
+if (Val.getAsInteger(0, SelectedFunctionGroup) ||
+SelectedFunctionGroup < 0 || SelectedFunctionGroup >= FunctionGroups)
+  D.Diag(diag::err_drv_invalid_int_value) << A->getAsString(Args) << Val;
+  }
+  if (FunctionGroups != 1)
+CmdArgs.push_back(Args.MakeArgString("-fprofile-function-groups=" +
+ Twine(FunctionGroups)));
+  if (SelectedFunctionGroup != 0)
+CmdArgs.push_back(Args.MakeArgString("-fprofile-selected-function-group=" +
+ Twine(SelectedFunctionGroup)));
+
   // Leave -fprofile-dir= an unused argument unless .gcda emission is
   // enabled. To be polite, with '-fprofile-arcs -fno-profile-arcs' consider
   // the flag used. There is no -fno-profile-dir, so the user has no
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1326,9 +1326,15 @@
   bool imbueXRayAttrs(llvm::Function *Fn, SourceLocation Loc,
   StringRef Category = StringRef()) const;
 
-  /// Returns true if function at the given location should b

[PATCH] D129594: [InstrProf] Add options to profile function groups

2022-07-14 Thread Ellis Hoag via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaf58684f2720: [InstrProf] Add options to profile function 
groups (authored by ellis).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129594/new/

https://reviews.llvm.org/D129594

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/docs/UsersManual.rst
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/profile-function-groups.c
  compiler-rt/test/profile/instrprof-groups.c

Index: compiler-rt/test/profile/instrprof-groups.c
===
--- /dev/null
+++ compiler-rt/test/profile/instrprof-groups.c
@@ -0,0 +1,28 @@
+// RUN: %clang_pgogen -fprofile-function-groups=3 -fprofile-selected-function-group=0 %s -o %t.0.out
+// RUN: %clang_pgogen -fprofile-function-groups=3 -fprofile-selected-function-group=1 %s -o %t.1.out
+// RUN: %clang_pgogen -fprofile-function-groups=3 -fprofile-selected-function-group=2 %s -o %t.2.out
+// RUN: env LLVM_PROFILE_FILE=%t.0.profraw %run %t.0.out
+// RUN: env LLVM_PROFILE_FILE=%t.1.profraw %run %t.1.out
+// RUN: env LLVM_PROFILE_FILE=%t.2.profraw %run %t.2.out
+// RUN: llvm-profdata merge -o %t.profdata %t.*.profraw
+// RUN: llvm-profdata show %t.profdata --all-functions | FileCheck %s
+
+int foo(int i) { return 4 * i + 1; }
+int bar(int i) { return 4 * i + 2; }
+int goo(int i) { return 4 * i + 3; }
+
+int main(int argc, char *argv[]) {
+  foo(5);
+  bar(6);
+  goo(7);
+  return 0;
+}
+
+// Even though we ran this code three times, we expect all counts to be one if
+// functions were partitioned into groups correctly.
+
+// CHECK: Counters: 1
+// CHECK: Counters: 1
+// CHECK: Counters: 1
+// CHECK: Counters: 1
+// CHECK: Total functions: 4
Index: clang/test/CodeGen/profile-function-groups.c
===
--- /dev/null
+++ clang/test/CodeGen/profile-function-groups.c
@@ -0,0 +1,24 @@
+// RUN: %clang -fprofile-generate -fprofile-function-groups=3 -fprofile-selected-function-group=0 -emit-llvm -S %s -o - | FileCheck %s --check-prefixes=CHECK,SELECT0
+// RUN: %clang -fprofile-generate -fprofile-function-groups=3 -fprofile-selected-function-group=1 -emit-llvm -S %s -o - | FileCheck %s --check-prefixes=CHECK,SELECT1
+// RUN: %clang -fprofile-generate -fprofile-function-groups=3 -fprofile-selected-function-group=2 -emit-llvm -S %s -o - | FileCheck %s --check-prefixes=CHECK,SELECT2
+
+// Group 0
+// SELECT0-NOT: noprofile
+// SELECT1: noprofile
+// SELECT2: noprofile
+// CHECK: define {{.*}} @hoo()
+void hoo() {}
+
+// Group 1
+// SELECT0: noprofile
+// SELECT1-NOT: noprofile
+// SELECT2: noprofile
+// CHECK: define {{.*}} @goo()
+void goo() {}
+
+// Group 2
+// SELECT0: noprofile
+// SELECT1: noprofile
+// SELECT2-NOT: noprofile
+// CHECK: define {{.*}} @boo()
+void boo() {}
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -956,6 +956,27 @@
 CmdArgs.push_back("-fprofile-update=atomic");
   }
 
+  int FunctionGroups = 1;
+  int SelectedFunctionGroup = 0;
+  if (const auto *A = Args.getLastArg(options::OPT_fprofile_function_groups)) {
+StringRef Val = A->getValue();
+if (Val.getAsInteger(0, FunctionGroups) || FunctionGroups < 1)
+  D.Diag(diag::err_drv_invalid_int_value) << A->getAsString(Args) << Val;
+  }
+  if (const auto *A =
+  Args.getLastArg(options::OPT_fprofile_selected_function_group)) {
+StringRef Val = A->getValue();
+if (Val.getAsInteger(0, SelectedFunctionGroup) ||
+SelectedFunctionGroup < 0 || SelectedFunctionGroup >= FunctionGroups)
+  D.Diag(diag::err_drv_invalid_int_value) << A->getAsString(Args) << Val;
+  }
+  if (FunctionGroups != 1)
+CmdArgs.push_back(Args.MakeArgString("-fprofile-function-groups=" +
+ Twine(FunctionGroups)));
+  if (SelectedFunctionGroup != 0)
+CmdArgs.push_back(Args.MakeArgString("-fprofile-selected-function-group=" +
+ Twine(SelectedFunctionGroup)));
+
   // Leave -fprofile-dir= an unused argument unless .gcda emission is
   // enabled. To be polite, with '-fprofile-arcs -fno-profile-arcs' consider
   // the flag used. There is no -fno-profile-dir, so the user has no
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1340,9 +1340,15 @@
   bool imbueXRayAttrs(llvm::Function *Fn, SourceLocation Loc,
   StringRef Category = StringRef()) const;
 
-  /// Returns t

[PATCH] D88329: [objc] Consolidate ObjC name mangle code to AST

2020-09-25 Thread Ellis Hoag via Phabricator via cfe-commits
ellis created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
ellis requested review of this revision.

This reduces code duplication between CGObjCMac.cpp and Mangle.cpp for 
generating the mangled name of an Objective-C method.

This has no intended functionality change.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88329

Files:
  clang/include/clang/AST/Mangle.h
  clang/lib/AST/Mangle.cpp
  clang/lib/CodeGen/CGObjCMac.cpp

Index: clang/lib/CodeGen/CGObjCMac.cpp
===
--- clang/lib/CodeGen/CGObjCMac.cpp
+++ clang/lib/CodeGen/CGObjCMac.cpp
@@ -20,6 +20,7 @@
 #include "clang/AST/Attr.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclObjC.h"
+#include "clang/AST/Mangle.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/AST/StmtObjC.h"
 #include "clang/Basic/CodeGenOptions.h"
@@ -924,13 +925,6 @@
 
   llvm::StringMap NSConstantStringMap;
 
-  /// GetNameForMethod - Return a name for the given method.
-  /// \param[out] NameOut - The return value.
-  void GetNameForMethod(const ObjCMethodDecl *OMD,
-const ObjCContainerDecl *CD,
-SmallVectorImpl &NameOut,
-bool ignoreCategoryNamespace = false);
-
   /// GetMethodVarName - Return a unique constant for the given
   /// selector's name. The return value has type char *.
   llvm::Constant *GetMethodVarName(Selector Sel);
@@ -4008,7 +4002,10 @@
 Method = GenerateDirectMethod(OMD, CD);
   } else {
 SmallString<256> Name;
-GetNameForMethod(OMD, CD, Name);
+llvm::raw_svector_ostream OS(Name);
+const auto &MC = CGM.getContext().createMangleContext();
+MC->mangleObjCMethodNameWithoutSize(OMD, OS, /*includePrefixByte=*/true,
+/*includeCategoryNamespace=*/true);
 
 CodeGenTypes &Types = CGM.getTypes();
 llvm::FunctionType *MethodTy =
@@ -4061,7 +4058,10 @@
 I->second = Fn;
   } else {
 SmallString<256> Name;
-GetNameForMethod(OMD, CD, Name, /*ignoreCategoryNamespace*/ true);
+llvm::raw_svector_ostream OS(Name);
+const auto &MC = CGM.getContext().createMangleContext();
+MC->mangleObjCMethodNameWithoutSize(OMD, OS, /*includePrefixByte=*/true,
+/*includeCategoryNamespace=*/false);
 
 Fn = llvm::Function::Create(MethodTy, llvm::GlobalValue::ExternalLinkage,
 Name.str(), &CGM.getModule());
@@ -5715,21 +5715,6 @@
   return GetPropertyName(&CGM.getContext().Idents.get(TypeStr));
 }
 
-void CGObjCCommonMac::GetNameForMethod(const ObjCMethodDecl *D,
-   const ObjCContainerDecl *CD,
-   SmallVectorImpl &Name,
-   bool ignoreCategoryNamespace) {
-  llvm::raw_svector_ostream OS(Name);
-  assert (CD && "Missing container decl in GetNameForMethod");
-  OS << '\01' << (D->isInstanceMethod() ? '-' : '+')
- << '[' << CD->getName();
-  if (!ignoreCategoryNamespace)
-if (const ObjCCategoryImplDecl *CID =
-dyn_cast(D->getDeclContext()))
-  OS << '(' << *CID << ')';
-  OS << ' ' << D->getSelector().getAsString() << ']';
-}
-
 void CGObjCMac::FinishModule() {
   EmitModuleInfo();
 
Index: clang/lib/AST/Mangle.cpp
===
--- clang/lib/AST/Mangle.cpp
+++ clang/lib/AST/Mangle.cpp
@@ -304,17 +304,23 @@
   mangleFunctionBlock(*this, Buffer, BD, Out);
 }
 
-void MangleContext::mangleObjCMethodNameWithoutSize(const ObjCMethodDecl *MD,
-raw_ostream &OS) {
-  const ObjCContainerDecl *CD =
-  dyn_cast(MD->getDeclContext());
-  assert (CD && "Missing container decl in GetNameForMethod");
+void MangleContext::mangleObjCMethodNameWithoutSize(
+const ObjCMethodDecl *MD, raw_ostream &OS, bool includePrefixByte,
+bool includeCategoryNamespace) {
+  // \01+[ContainerName(CategoryName) SelectorName]
+  if (includePrefixByte) {
+OS << '\01';
+  }
   OS << (MD->isInstanceMethod() ? '-' : '+') << '[';
-  if (const ObjCCategoryImplDecl *CID = dyn_cast(CD)) {
+  if (auto *CID = dyn_cast(MD->getDeclContext())) {
 OS << CID->getClassInterface()->getName();
-OS << '(' << *CID << ')';
-  } else {
+if (includeCategoryNamespace) {
+  OS << '(' << *CID << ')';
+}
+  } else if (auto *CD = dyn_cast(MD->getDeclContext())) {
 OS << CD->getName();
+  } else {
+assert(false && "Unexpected ObjC method decl context");
   }
   OS << ' ';
   MD->getSelector().print(OS);
@@ -326,7 +332,8 @@
   SmallString<64> Name;
   llvm::raw_svector_ostream OS(Name);
 
-  mangleObjCMethodNameWithoutSize(MD, OS);
+  mangleObjCMethodNameWithoutSize(MD, OS, /*includePrefixByte=*/false,
+  /*includeCategoryNamespace=*/true);
   Out << OS.str().size() << OS.str();
 }
 
@@ -

[PATCH] D88329: [objc] Consolidate ObjC name mangle code to AST

2020-09-25 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 294395.
ellis added a comment.

Fix variable name


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88329/new/

https://reviews.llvm.org/D88329

Files:
  clang/include/clang/AST/Mangle.h
  clang/lib/AST/Mangle.cpp
  clang/lib/CodeGen/CGObjCMac.cpp

Index: clang/lib/CodeGen/CGObjCMac.cpp
===
--- clang/lib/CodeGen/CGObjCMac.cpp
+++ clang/lib/CodeGen/CGObjCMac.cpp
@@ -20,6 +20,7 @@
 #include "clang/AST/Attr.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclObjC.h"
+#include "clang/AST/Mangle.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/AST/StmtObjC.h"
 #include "clang/Basic/CodeGenOptions.h"
@@ -924,13 +925,6 @@
 
   llvm::StringMap NSConstantStringMap;
 
-  /// GetNameForMethod - Return a name for the given method.
-  /// \param[out] NameOut - The return value.
-  void GetNameForMethod(const ObjCMethodDecl *OMD,
-const ObjCContainerDecl *CD,
-SmallVectorImpl &NameOut,
-bool ignoreCategoryNamespace = false);
-
   /// GetMethodVarName - Return a unique constant for the given
   /// selector's name. The return value has type char *.
   llvm::Constant *GetMethodVarName(Selector Sel);
@@ -4008,7 +4002,10 @@
 Method = GenerateDirectMethod(OMD, CD);
   } else {
 SmallString<256> Name;
-GetNameForMethod(OMD, CD, Name);
+llvm::raw_svector_ostream OS(Name);
+const auto &MC = CGM.getContext().createMangleContext();
+MC->mangleObjCMethodNameWithoutSize(OMD, OS, /*includePrefixByte=*/true,
+/*includeCategoryNamespace=*/true);
 
 CodeGenTypes &Types = CGM.getTypes();
 llvm::FunctionType *MethodTy =
@@ -4061,7 +4058,10 @@
 I->second = Fn;
   } else {
 SmallString<256> Name;
-GetNameForMethod(OMD, CD, Name, /*ignoreCategoryNamespace*/ true);
+llvm::raw_svector_ostream OS(Name);
+const auto &MC = CGM.getContext().createMangleContext();
+MC->mangleObjCMethodNameWithoutSize(OMD, OS, /*includePrefixByte=*/true,
+/*includeCategoryNamespace=*/false);
 
 Fn = llvm::Function::Create(MethodTy, llvm::GlobalValue::ExternalLinkage,
 Name.str(), &CGM.getModule());
@@ -5715,21 +5715,6 @@
   return GetPropertyName(&CGM.getContext().Idents.get(TypeStr));
 }
 
-void CGObjCCommonMac::GetNameForMethod(const ObjCMethodDecl *D,
-   const ObjCContainerDecl *CD,
-   SmallVectorImpl &Name,
-   bool ignoreCategoryNamespace) {
-  llvm::raw_svector_ostream OS(Name);
-  assert (CD && "Missing container decl in GetNameForMethod");
-  OS << '\01' << (D->isInstanceMethod() ? '-' : '+')
- << '[' << CD->getName();
-  if (!ignoreCategoryNamespace)
-if (const ObjCCategoryImplDecl *CID =
-dyn_cast(D->getDeclContext()))
-  OS << '(' << *CID << ')';
-  OS << ' ' << D->getSelector().getAsString() << ']';
-}
-
 void CGObjCMac::FinishModule() {
   EmitModuleInfo();
 
Index: clang/lib/AST/Mangle.cpp
===
--- clang/lib/AST/Mangle.cpp
+++ clang/lib/AST/Mangle.cpp
@@ -304,17 +304,23 @@
   mangleFunctionBlock(*this, Buffer, BD, Out);
 }
 
-void MangleContext::mangleObjCMethodNameWithoutSize(const ObjCMethodDecl *MD,
-raw_ostream &OS) {
-  const ObjCContainerDecl *CD =
-  dyn_cast(MD->getDeclContext());
-  assert (CD && "Missing container decl in GetNameForMethod");
+void MangleContext::mangleObjCMethodNameWithoutSize(
+const ObjCMethodDecl *MD, raw_ostream &OS, bool includePrefixByte,
+bool includeCategoryNamespace) {
+  // \01+[ContainerName(CategoryName) SelectorName]
+  if (includePrefixByte) {
+OS << '\01';
+  }
   OS << (MD->isInstanceMethod() ? '-' : '+') << '[';
-  if (const ObjCCategoryImplDecl *CID = dyn_cast(CD)) {
+  if (auto *CID = dyn_cast(MD->getDeclContext())) {
 OS << CID->getClassInterface()->getName();
-OS << '(' << *CID << ')';
-  } else {
+if (includeCategoryNamespace) {
+  OS << '(' << *CID << ')';
+}
+  } else if (auto *CD = dyn_cast(MD->getDeclContext())) {
 OS << CD->getName();
+  } else {
+assert(false && "Unexpected ObjC method decl context");
   }
   OS << ' ';
   MD->getSelector().print(OS);
@@ -326,7 +332,8 @@
   SmallString<64> Name;
   llvm::raw_svector_ostream OS(Name);
 
-  mangleObjCMethodNameWithoutSize(MD, OS);
+  mangleObjCMethodNameWithoutSize(MD, OS, /*includePrefixByte=*/false,
+  /*includeCategoryNamespace=*/true);
   Out << OS.str().size() << OS.str();
 }
 
@@ -352,7 +359,8 @@
   if (writeFuncOrVarName(VD, FrontendBufOS))
 return true;
 } else if (auto *MD = dyn_cast(D)) {
-  MC->mangleObjCMethodNam

[PATCH] D88329: [objc] Consolidate ObjC name mangle code to AST

2020-09-25 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 294461.
ellis added a comment.

Rename `mangleObjCMethodName`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88329/new/

https://reviews.llvm.org/D88329

Files:
  clang/include/clang/AST/Mangle.h
  clang/lib/AST/Mangle.cpp
  clang/lib/CodeGen/CGObjCMac.cpp

Index: clang/lib/CodeGen/CGObjCMac.cpp
===
--- clang/lib/CodeGen/CGObjCMac.cpp
+++ clang/lib/CodeGen/CGObjCMac.cpp
@@ -20,6 +20,7 @@
 #include "clang/AST/Attr.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclObjC.h"
+#include "clang/AST/Mangle.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/AST/StmtObjC.h"
 #include "clang/Basic/CodeGenOptions.h"
@@ -924,13 +925,6 @@
 
   llvm::StringMap NSConstantStringMap;
 
-  /// GetNameForMethod - Return a name for the given method.
-  /// \param[out] NameOut - The return value.
-  void GetNameForMethod(const ObjCMethodDecl *OMD,
-const ObjCContainerDecl *CD,
-SmallVectorImpl &NameOut,
-bool ignoreCategoryNamespace = false);
-
   /// GetMethodVarName - Return a unique constant for the given
   /// selector's name. The return value has type char *.
   llvm::Constant *GetMethodVarName(Selector Sel);
@@ -4008,7 +4002,10 @@
 Method = GenerateDirectMethod(OMD, CD);
   } else {
 SmallString<256> Name;
-GetNameForMethod(OMD, CD, Name);
+llvm::raw_svector_ostream OS(Name);
+const auto &MC = CGM.getContext().createMangleContext();
+MC->mangleObjCMethodName(OMD, OS, /*includePrefixByte=*/true,
+ /*includeCategoryNamespace=*/true);
 
 CodeGenTypes &Types = CGM.getTypes();
 llvm::FunctionType *MethodTy =
@@ -4061,7 +4058,10 @@
 I->second = Fn;
   } else {
 SmallString<256> Name;
-GetNameForMethod(OMD, CD, Name, /*ignoreCategoryNamespace*/ true);
+llvm::raw_svector_ostream OS(Name);
+const auto &MC = CGM.getContext().createMangleContext();
+MC->mangleObjCMethodName(OMD, OS, /*includePrefixByte=*/true,
+ /*includeCategoryNamespace=*/false);
 
 Fn = llvm::Function::Create(MethodTy, llvm::GlobalValue::ExternalLinkage,
 Name.str(), &CGM.getModule());
@@ -5715,21 +5715,6 @@
   return GetPropertyName(&CGM.getContext().Idents.get(TypeStr));
 }
 
-void CGObjCCommonMac::GetNameForMethod(const ObjCMethodDecl *D,
-   const ObjCContainerDecl *CD,
-   SmallVectorImpl &Name,
-   bool ignoreCategoryNamespace) {
-  llvm::raw_svector_ostream OS(Name);
-  assert (CD && "Missing container decl in GetNameForMethod");
-  OS << '\01' << (D->isInstanceMethod() ? '-' : '+')
- << '[' << CD->getName();
-  if (!ignoreCategoryNamespace)
-if (const ObjCCategoryImplDecl *CID =
-dyn_cast(D->getDeclContext()))
-  OS << '(' << *CID << ')';
-  OS << ' ' << D->getSelector().getAsString() << ']';
-}
-
 void CGObjCMac::FinishModule() {
   EmitModuleInfo();
 
Index: clang/lib/AST/Mangle.cpp
===
--- clang/lib/AST/Mangle.cpp
+++ clang/lib/AST/Mangle.cpp
@@ -175,7 +175,7 @@
   const TargetInfo &TI = Context.getTargetInfo();
   if (CC == CCM_Other || (MCXX && TI.getCXXABI() == TargetCXXABI::Microsoft)) {
 if (const ObjCMethodDecl *OMD = dyn_cast(D))
-  mangleObjCMethodName(OMD, Out);
+  mangleObjCMethodNameAsSourceName(OMD, Out);
 else
   mangleCXXName(GD, Out);
 return;
@@ -192,7 +192,7 @@
   if (!MCXX)
 Out << D->getIdentifier()->getName();
   else if (const ObjCMethodDecl *OMD = dyn_cast(D))
-mangleObjCMethodName(OMD, Out);
+mangleObjCMethodNameAsSourceName(OMD, Out);
   else
 mangleCXXName(GD, Out);
 
@@ -275,7 +275,7 @@
   SmallString<64> Buffer;
   llvm::raw_svector_ostream Stream(Buffer);
   if (const ObjCMethodDecl *Method = dyn_cast(DC)) {
-mangleObjCMethodName(Method, Stream);
+mangleObjCMethodNameAsSourceName(Method, Stream);
   } else {
 assert((isa(DC) || isa(DC)) &&
"expected a NamedDecl or BlockDecl");
@@ -304,29 +304,38 @@
   mangleFunctionBlock(*this, Buffer, BD, Out);
 }
 
-void MangleContext::mangleObjCMethodNameWithoutSize(const ObjCMethodDecl *MD,
-raw_ostream &OS) {
-  const ObjCContainerDecl *CD =
-  dyn_cast(MD->getDeclContext());
-  assert (CD && "Missing container decl in GetNameForMethod");
+void MangleContext::mangleObjCMethodName(const ObjCMethodDecl *MD,
+ raw_ostream &OS,
+ bool includePrefixByte,
+ bool includeCategoryNamespace) {
+  // \01+[ContainerName(CategoryName) SelectorName]
+  if (includePrefixByte) {
+OS << '\01';
+  }
   OS <

[PATCH] D88329: [objc] Consolidate ObjC name mangle code to AST

2020-09-26 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 294503.
ellis added a comment.

Update call sites


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88329/new/

https://reviews.llvm.org/D88329

Files:
  clang/include/clang/AST/Mangle.h
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/Mangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/CodeGen/CGObjCMac.cpp

Index: clang/lib/CodeGen/CGObjCMac.cpp
===
--- clang/lib/CodeGen/CGObjCMac.cpp
+++ clang/lib/CodeGen/CGObjCMac.cpp
@@ -20,6 +20,7 @@
 #include "clang/AST/Attr.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclObjC.h"
+#include "clang/AST/Mangle.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/AST/StmtObjC.h"
 #include "clang/Basic/CodeGenOptions.h"
@@ -924,13 +925,6 @@
 
   llvm::StringMap NSConstantStringMap;
 
-  /// GetNameForMethod - Return a name for the given method.
-  /// \param[out] NameOut - The return value.
-  void GetNameForMethod(const ObjCMethodDecl *OMD,
-const ObjCContainerDecl *CD,
-SmallVectorImpl &NameOut,
-bool ignoreCategoryNamespace = false);
-
   /// GetMethodVarName - Return a unique constant for the given
   /// selector's name. The return value has type char *.
   llvm::Constant *GetMethodVarName(Selector Sel);
@@ -4008,7 +4002,10 @@
 Method = GenerateDirectMethod(OMD, CD);
   } else {
 SmallString<256> Name;
-GetNameForMethod(OMD, CD, Name);
+llvm::raw_svector_ostream OS(Name);
+const auto &MC = CGM.getContext().createMangleContext();
+MC->mangleObjCMethodName(OMD, OS, /*includePrefixByte=*/true,
+ /*includeCategoryNamespace=*/true);
 
 CodeGenTypes &Types = CGM.getTypes();
 llvm::FunctionType *MethodTy =
@@ -4061,7 +4058,10 @@
 I->second = Fn;
   } else {
 SmallString<256> Name;
-GetNameForMethod(OMD, CD, Name, /*ignoreCategoryNamespace*/ true);
+llvm::raw_svector_ostream OS(Name);
+const auto &MC = CGM.getContext().createMangleContext();
+MC->mangleObjCMethodName(OMD, OS, /*includePrefixByte=*/true,
+ /*includeCategoryNamespace=*/false);
 
 Fn = llvm::Function::Create(MethodTy, llvm::GlobalValue::ExternalLinkage,
 Name.str(), &CGM.getModule());
@@ -5715,21 +5715,6 @@
   return GetPropertyName(&CGM.getContext().Idents.get(TypeStr));
 }
 
-void CGObjCCommonMac::GetNameForMethod(const ObjCMethodDecl *D,
-   const ObjCContainerDecl *CD,
-   SmallVectorImpl &Name,
-   bool ignoreCategoryNamespace) {
-  llvm::raw_svector_ostream OS(Name);
-  assert (CD && "Missing container decl in GetNameForMethod");
-  OS << '\01' << (D->isInstanceMethod() ? '-' : '+')
- << '[' << CD->getName();
-  if (!ignoreCategoryNamespace)
-if (const ObjCCategoryImplDecl *CID =
-dyn_cast(D->getDeclContext()))
-  OS << '(' << *CID << ')';
-  OS << ' ' << D->getSelector().getAsString() << ']';
-}
-
 void CGObjCMac::FinishModule() {
   EmitModuleInfo();
 
Index: clang/lib/AST/MicrosoftMangle.cpp
===
--- clang/lib/AST/MicrosoftMangle.cpp
+++ clang/lib/AST/MicrosoftMangle.cpp
@@ -1323,7 +1323,7 @@
 }
 
 void MicrosoftCXXNameMangler::mangleObjCMethodName(const ObjCMethodDecl *MD) {
-  Context.mangleObjCMethodName(MD, Out);
+  Context.mangleObjCMethodNameAsSourceName(MD, Out);
 }
 
 void MicrosoftCXXNameMangler::mangleTemplateInstantiationName(
Index: clang/lib/AST/Mangle.cpp
===
--- clang/lib/AST/Mangle.cpp
+++ clang/lib/AST/Mangle.cpp
@@ -175,7 +175,7 @@
   const TargetInfo &TI = Context.getTargetInfo();
   if (CC == CCM_Other || (MCXX && TI.getCXXABI() == TargetCXXABI::Microsoft)) {
 if (const ObjCMethodDecl *OMD = dyn_cast(D))
-  mangleObjCMethodName(OMD, Out);
+  mangleObjCMethodNameAsSourceName(OMD, Out);
 else
   mangleCXXName(GD, Out);
 return;
@@ -192,7 +192,7 @@
   if (!MCXX)
 Out << D->getIdentifier()->getName();
   else if (const ObjCMethodDecl *OMD = dyn_cast(D))
-mangleObjCMethodName(OMD, Out);
+mangleObjCMethodNameAsSourceName(OMD, Out);
   else
 mangleCXXName(GD, Out);
 
@@ -275,7 +275,7 @@
   SmallString<64> Buffer;
   llvm::raw_svector_ostream Stream(Buffer);
   if (const ObjCMethodDecl *Method = dyn_cast(DC)) {
-mangleObjCMethodName(Method, Stream);
+mangleObjCMethodNameAsSourceName(Method, Stream);
   } else {
 assert((isa(DC) || isa(DC)) &&
"expected a NamedDecl or BlockDecl");
@@ -304,29 +304,38 @@
   mangleFunctionBlock(*this, Buffer, BD, Out);
 }
 
-void MangleContext::mangleObjCMethodNameWithoutSize(const ObjCMethodDecl *MD,
-raw_ostream &OS

[PATCH] D88329: [objc] Consolidate ObjC name mangle code to AST

2020-09-26 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added a comment.

Thanks for accepting @rjmccall. Could you land this? I don't have commit access 
yet.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88329/new/

https://reviews.llvm.org/D88329

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


[PATCH] D88329: [objc] Consolidate ObjC name mangle code to AST

2020-09-29 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 295000.
ellis added a comment.

[objc] Fix memory leak in CGObjCMac.cpp

CGObjCMac.cpp was leaking a MangleContext everytime it mangled an ObjC method. 
We now have an instance variable that allocates and deallocates the context.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88329/new/

https://reviews.llvm.org/D88329

Files:
  clang/include/clang/AST/Mangle.h
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/Mangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/CodeGen/CGObjCMac.cpp

Index: clang/lib/CodeGen/CGObjCMac.cpp
===
--- clang/lib/CodeGen/CGObjCMac.cpp
+++ clang/lib/CodeGen/CGObjCMac.cpp
@@ -20,6 +20,7 @@
 #include "clang/AST/Attr.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclObjC.h"
+#include "clang/AST/Mangle.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/AST/StmtObjC.h"
 #include "clang/Basic/CodeGenOptions.h"
@@ -924,13 +925,6 @@
 
   llvm::StringMap NSConstantStringMap;
 
-  /// GetNameForMethod - Return a name for the given method.
-  /// \param[out] NameOut - The return value.
-  void GetNameForMethod(const ObjCMethodDecl *OMD,
-const ObjCContainerDecl *CD,
-SmallVectorImpl &NameOut,
-bool ignoreCategoryNamespace = false);
-
   /// GetMethodVarName - Return a unique constant for the given
   /// selector's name. The return value has type char *.
   llvm::Constant *GetMethodVarName(Selector Sel);
@@ -1086,7 +1080,7 @@
 
 public:
   CGObjCCommonMac(CodeGen::CodeGenModule &cgm) :
-CGObjCRuntime(cgm), VMContext(cgm.getLLVMContext()) { }
+CGObjCRuntime(cgm), VMContext(cgm.getLLVMContext()), Mangler(cgm.getContext().createMangleContext()) { }
 
   bool isNonFragileABI() const {
 return ObjCABI == 2;
@@ -1127,6 +1121,7 @@
 
 private:
   void fillRunSkipBlockVars(CodeGenModule &CGM, const CGBlockInfo &blockInfo);
+  std::unique_ptr Mangler;
 };
 
 namespace {
@@ -4008,7 +4003,9 @@
 Method = GenerateDirectMethod(OMD, CD);
   } else {
 SmallString<256> Name;
-GetNameForMethod(OMD, CD, Name);
+llvm::raw_svector_ostream OS(Name);
+Mangler->mangleObjCMethodName(OMD, OS, /*includePrefixByte=*/true,
+ /*includeCategoryNamespace=*/true);
 
 CodeGenTypes &Types = CGM.getTypes();
 llvm::FunctionType *MethodTy =
@@ -4061,7 +4058,9 @@
 I->second = Fn;
   } else {
 SmallString<256> Name;
-GetNameForMethod(OMD, CD, Name, /*ignoreCategoryNamespace*/ true);
+llvm::raw_svector_ostream OS(Name);
+Mangler->mangleObjCMethodName(OMD, OS, /*includePrefixByte=*/true,
+ /*includeCategoryNamespace=*/false);
 
 Fn = llvm::Function::Create(MethodTy, llvm::GlobalValue::ExternalLinkage,
 Name.str(), &CGM.getModule());
@@ -5715,21 +5714,6 @@
   return GetPropertyName(&CGM.getContext().Idents.get(TypeStr));
 }
 
-void CGObjCCommonMac::GetNameForMethod(const ObjCMethodDecl *D,
-   const ObjCContainerDecl *CD,
-   SmallVectorImpl &Name,
-   bool ignoreCategoryNamespace) {
-  llvm::raw_svector_ostream OS(Name);
-  assert (CD && "Missing container decl in GetNameForMethod");
-  OS << '\01' << (D->isInstanceMethod() ? '-' : '+')
- << '[' << CD->getName();
-  if (!ignoreCategoryNamespace)
-if (const ObjCCategoryImplDecl *CID =
-dyn_cast(D->getDeclContext()))
-  OS << '(' << *CID << ')';
-  OS << ' ' << D->getSelector().getAsString() << ']';
-}
-
 void CGObjCMac::FinishModule() {
   EmitModuleInfo();
 
Index: clang/lib/AST/MicrosoftMangle.cpp
===
--- clang/lib/AST/MicrosoftMangle.cpp
+++ clang/lib/AST/MicrosoftMangle.cpp
@@ -1323,7 +1323,7 @@
 }
 
 void MicrosoftCXXNameMangler::mangleObjCMethodName(const ObjCMethodDecl *MD) {
-  Context.mangleObjCMethodName(MD, Out);
+  Context.mangleObjCMethodNameAsSourceName(MD, Out);
 }
 
 void MicrosoftCXXNameMangler::mangleTemplateInstantiationName(
Index: clang/lib/AST/Mangle.cpp
===
--- clang/lib/AST/Mangle.cpp
+++ clang/lib/AST/Mangle.cpp
@@ -175,7 +175,7 @@
   const TargetInfo &TI = Context.getTargetInfo();
   if (CC == CCM_Other || (MCXX && TI.getCXXABI() == TargetCXXABI::Microsoft)) {
 if (const ObjCMethodDecl *OMD = dyn_cast(D))
-  mangleObjCMethodName(OMD, Out);
+  mangleObjCMethodNameAsSourceName(OMD, Out);
 else
   mangleCXXName(GD, Out);
 return;
@@ -192,7 +192,7 @@
   if (!MCXX)
 Out << D->getIdentifier()->getName();
   else if (const ObjCMethodDecl *OMD = dyn_cast(D))
-mangleObjCMethodName(OMD, Out);
+mangleObjCMethodNameAsSourceName(OMD, Out);
   else
 mangleCXXName(GD, Out);
 
@@ -275,7 +275,7 @@
   

[PATCH] D88329: [objc] Consolidate ObjC name mangle code to AST

2020-09-29 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added a comment.

Oops, I meant to create a new commit rather than amend to this one


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88329/new/

https://reviews.llvm.org/D88329

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


[PATCH] D88497: [objc] Fix memory leak in CGObjCMac.cpp

2020-09-29 Thread Ellis Hoag via Phabricator via cfe-commits
ellis created this revision.
ellis added a reviewer: rjmccall.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
ellis requested review of this revision.

A memory leak was introduced in https://reviews.llvm.org/D88329

CGObjCMac.cpp was leaking a MangleContext everytime it mangled
an ObjC method. We now have an instance variable that allocates
and deallocates the context.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88497

Files:
  clang/lib/CodeGen/CGObjCMac.cpp


Index: clang/lib/CodeGen/CGObjCMac.cpp
===
--- clang/lib/CodeGen/CGObjCMac.cpp
+++ clang/lib/CodeGen/CGObjCMac.cpp
@@ -1079,8 +1079,9 @@
   void EmitImageInfo();
 
 public:
-  CGObjCCommonMac(CodeGen::CodeGenModule &cgm) :
-CGObjCRuntime(cgm), VMContext(cgm.getLLVMContext()) { }
+  CGObjCCommonMac(CodeGen::CodeGenModule &cgm)
+  : CGObjCRuntime(cgm), VMContext(cgm.getLLVMContext()),
+Mangler(cgm.getContext().createMangleContext()) {}
 
   bool isNonFragileABI() const {
 return ObjCABI == 2;
@@ -1121,6 +1122,7 @@
 
 private:
   void fillRunSkipBlockVars(CodeGenModule &CGM, const CGBlockInfo &blockInfo);
+  std::unique_ptr Mangler;
 };
 
 namespace {
@@ -4003,9 +4005,8 @@
   } else {
 SmallString<256> Name;
 llvm::raw_svector_ostream OS(Name);
-const auto &MC = CGM.getContext().createMangleContext();
-MC->mangleObjCMethodName(OMD, OS, /*includePrefixByte=*/true,
- /*includeCategoryNamespace=*/true);
+Mangler->mangleObjCMethodName(OMD, OS, /*includePrefixByte=*/true,
+  /*includeCategoryNamespace=*/true);
 
 CodeGenTypes &Types = CGM.getTypes();
 llvm::FunctionType *MethodTy =
@@ -4059,9 +4060,8 @@
   } else {
 SmallString<256> Name;
 llvm::raw_svector_ostream OS(Name);
-const auto &MC = CGM.getContext().createMangleContext();
-MC->mangleObjCMethodName(OMD, OS, /*includePrefixByte=*/true,
- /*includeCategoryNamespace=*/false);
+Mangler->mangleObjCMethodName(OMD, OS, /*includePrefixByte=*/true,
+  /*includeCategoryNamespace=*/false);
 
 Fn = llvm::Function::Create(MethodTy, llvm::GlobalValue::ExternalLinkage,
 Name.str(), &CGM.getModule());


Index: clang/lib/CodeGen/CGObjCMac.cpp
===
--- clang/lib/CodeGen/CGObjCMac.cpp
+++ clang/lib/CodeGen/CGObjCMac.cpp
@@ -1079,8 +1079,9 @@
   void EmitImageInfo();
 
 public:
-  CGObjCCommonMac(CodeGen::CodeGenModule &cgm) :
-CGObjCRuntime(cgm), VMContext(cgm.getLLVMContext()) { }
+  CGObjCCommonMac(CodeGen::CodeGenModule &cgm)
+  : CGObjCRuntime(cgm), VMContext(cgm.getLLVMContext()),
+Mangler(cgm.getContext().createMangleContext()) {}
 
   bool isNonFragileABI() const {
 return ObjCABI == 2;
@@ -1121,6 +1122,7 @@
 
 private:
   void fillRunSkipBlockVars(CodeGenModule &CGM, const CGBlockInfo &blockInfo);
+  std::unique_ptr Mangler;
 };
 
 namespace {
@@ -4003,9 +4005,8 @@
   } else {
 SmallString<256> Name;
 llvm::raw_svector_ostream OS(Name);
-const auto &MC = CGM.getContext().createMangleContext();
-MC->mangleObjCMethodName(OMD, OS, /*includePrefixByte=*/true,
- /*includeCategoryNamespace=*/true);
+Mangler->mangleObjCMethodName(OMD, OS, /*includePrefixByte=*/true,
+  /*includeCategoryNamespace=*/true);
 
 CodeGenTypes &Types = CGM.getTypes();
 llvm::FunctionType *MethodTy =
@@ -4059,9 +4060,8 @@
   } else {
 SmallString<256> Name;
 llvm::raw_svector_ostream OS(Name);
-const auto &MC = CGM.getContext().createMangleContext();
-MC->mangleObjCMethodName(OMD, OS, /*includePrefixByte=*/true,
- /*includeCategoryNamespace=*/false);
+Mangler->mangleObjCMethodName(OMD, OS, /*includePrefixByte=*/true,
+  /*includeCategoryNamespace=*/false);
 
 Fn = llvm::Function::Create(MethodTy, llvm::GlobalValue::ExternalLinkage,
 Name.str(), &CGM.getModule());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D88329: [objc] Consolidate ObjC name mangle code to AST

2020-09-29 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added a comment.

https://reviews.llvm.org/D88497 will fix the leak


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88329/new/

https://reviews.llvm.org/D88329

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


[PATCH] D88497: [objc] Fix memory leak in CGObjCMac.cpp

2020-09-29 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added a comment.

Yes please commit for me :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88497/new/

https://reviews.llvm.org/D88497

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


[PATCH] D88497: [objc] Fix memory leak in CGObjCMac.cpp

2020-09-29 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 295055.
ellis added a subscriber: vsapsai.
ellis added a comment.
Herald added a reviewer: JDevlieghere.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Fix a comment to reference the correct method.

Thanks to @vsapsai for pointing this out.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88497/new/

https://reviews.llvm.org/D88497

Files:
  clang/lib/CodeGen/CGObjCMac.cpp
  llvm/tools/dsymutil/SymbolMap.cpp


Index: llvm/tools/dsymutil/SymbolMap.cpp
===
--- llvm/tools/dsymutil/SymbolMap.cpp
+++ llvm/tools/dsymutil/SymbolMap.cpp
@@ -47,7 +47,7 @@
 return Translation;
 
   // Objective-C symbols for the MachO symbol table start with a \1. Please see
-  // `CGObjCCommonMac::GetNameForMethod` in clang.
+  // `MangleContext::mangleObjCMethodName` in clang.
   if (Translation[0] == 1)
 return StringRef(Translation).drop_front();
 
Index: clang/lib/CodeGen/CGObjCMac.cpp
===
--- clang/lib/CodeGen/CGObjCMac.cpp
+++ clang/lib/CodeGen/CGObjCMac.cpp
@@ -1079,8 +1079,9 @@
   void EmitImageInfo();
 
 public:
-  CGObjCCommonMac(CodeGen::CodeGenModule &cgm) :
-CGObjCRuntime(cgm), VMContext(cgm.getLLVMContext()) { }
+  CGObjCCommonMac(CodeGen::CodeGenModule &cgm)
+  : CGObjCRuntime(cgm), VMContext(cgm.getLLVMContext()),
+Mangler(cgm.getContext().createMangleContext()) {}
 
   bool isNonFragileABI() const {
 return ObjCABI == 2;
@@ -1121,6 +1122,7 @@
 
 private:
   void fillRunSkipBlockVars(CodeGenModule &CGM, const CGBlockInfo &blockInfo);
+  std::unique_ptr Mangler;
 };
 
 namespace {
@@ -4003,9 +4005,8 @@
   } else {
 SmallString<256> Name;
 llvm::raw_svector_ostream OS(Name);
-const auto &MC = CGM.getContext().createMangleContext();
-MC->mangleObjCMethodName(OMD, OS, /*includePrefixByte=*/true,
- /*includeCategoryNamespace=*/true);
+Mangler->mangleObjCMethodName(OMD, OS, /*includePrefixByte=*/true,
+  /*includeCategoryNamespace=*/true);
 
 CodeGenTypes &Types = CGM.getTypes();
 llvm::FunctionType *MethodTy =
@@ -4059,9 +4060,8 @@
   } else {
 SmallString<256> Name;
 llvm::raw_svector_ostream OS(Name);
-const auto &MC = CGM.getContext().createMangleContext();
-MC->mangleObjCMethodName(OMD, OS, /*includePrefixByte=*/true,
- /*includeCategoryNamespace=*/false);
+Mangler->mangleObjCMethodName(OMD, OS, /*includePrefixByte=*/true,
+  /*includeCategoryNamespace=*/false);
 
 Fn = llvm::Function::Create(MethodTy, llvm::GlobalValue::ExternalLinkage,
 Name.str(), &CGM.getModule());


Index: llvm/tools/dsymutil/SymbolMap.cpp
===
--- llvm/tools/dsymutil/SymbolMap.cpp
+++ llvm/tools/dsymutil/SymbolMap.cpp
@@ -47,7 +47,7 @@
 return Translation;
 
   // Objective-C symbols for the MachO symbol table start with a \1. Please see
-  // `CGObjCCommonMac::GetNameForMethod` in clang.
+  // `MangleContext::mangleObjCMethodName` in clang.
   if (Translation[0] == 1)
 return StringRef(Translation).drop_front();
 
Index: clang/lib/CodeGen/CGObjCMac.cpp
===
--- clang/lib/CodeGen/CGObjCMac.cpp
+++ clang/lib/CodeGen/CGObjCMac.cpp
@@ -1079,8 +1079,9 @@
   void EmitImageInfo();
 
 public:
-  CGObjCCommonMac(CodeGen::CodeGenModule &cgm) :
-CGObjCRuntime(cgm), VMContext(cgm.getLLVMContext()) { }
+  CGObjCCommonMac(CodeGen::CodeGenModule &cgm)
+  : CGObjCRuntime(cgm), VMContext(cgm.getLLVMContext()),
+Mangler(cgm.getContext().createMangleContext()) {}
 
   bool isNonFragileABI() const {
 return ObjCABI == 2;
@@ -1121,6 +1122,7 @@
 
 private:
   void fillRunSkipBlockVars(CodeGenModule &CGM, const CGBlockInfo &blockInfo);
+  std::unique_ptr Mangler;
 };
 
 namespace {
@@ -4003,9 +4005,8 @@
   } else {
 SmallString<256> Name;
 llvm::raw_svector_ostream OS(Name);
-const auto &MC = CGM.getContext().createMangleContext();
-MC->mangleObjCMethodName(OMD, OS, /*includePrefixByte=*/true,
- /*includeCategoryNamespace=*/true);
+Mangler->mangleObjCMethodName(OMD, OS, /*includePrefixByte=*/true,
+  /*includeCategoryNamespace=*/true);
 
 CodeGenTypes &Types = CGM.getTypes();
 llvm::FunctionType *MethodTy =
@@ -4059,9 +4060,8 @@
   } else {
 SmallString<256> Name;
 llvm::raw_svector_ostream OS(Name);
-const auto &MC = CGM.getContext().createMangleContext();
-MC->mangleObjCMethodName(OMD, OS, /*includePrefixByte=*/true,
- /*includeCategoryNamespace=*/false);
+Mangler->mangleObjCMethodName(OMD, OS, /*includePrefixByte=*/true

[PATCH] D109703: [DebugInfo] Fix scope for local static variables

2021-09-22 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added a comment.

In D109703#2998350 , @krisb wrote:

> But it seems imported declarations are broken not just for static locals, but 
> for all inlined entities, for example
>
>   namespace ns {
>   inline __attribute__((always_inline))
>   int foo() {
> int a = 42; 
> return a;
>   }
>   }
>   
>   int main() {
> using ns::foo;
> return foo();
>   }
>
> produces (with or w/o this patch) imported declaration for `foo()` that 
> refers to an empty subprogram:
>
>   x002a:   DW_TAG_namespace
>   DW_AT_name  ("ns")
>   
>   0x002f: DW_TAG_subprogram
> DW_AT_name  ("foo")
> DW_AT_inline  (DW_INL_inlined)
>   
>   0x003f:   DW_TAG_variable
>   DW_AT_name  ("a")
>   
>   0x004a:   NULL
>   
>   0x004b: DW_TAG_subprogram
>   
>   0x004c: NULL
>   
>   0x0054:   DW_TAG_subprogram
>   DW_AT_name  ("main")
>   
>   0x006d: DW_TAG_imported_declaration
> DW_AT_import  (0x004b)
>
> while it should point to `0x002f`.

I've looked into this and realized that clang correctly emits a 
`DW_TAG_inlined_subroutine` for foo so the variables here are actually ok. The 
`DW_TAG_imported_declaration` tag is incorrect though, and I have a fix in 
https://reviews.llvm.org/D110294.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109703/new/

https://reviews.llvm.org/D109703

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


[PATCH] D109703: [DebugInfo] Fix scope for local static variables

2021-09-28 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added a comment.

In D109703#3018935 , @krisb wrote:

> @dblaikie yeah, the problem(s) seemed easier and smaller :(
>
> Basically, we have two issues with local scopes here:
> (1) function-scoped entities like static variables, type 
> definitions/typedefs, etc have incorrect (empty) parent DIE if the function 
> containing them was inlined. We do not consider abstract SP as a possible 
> parent DIE and try to create a new DIE for a function that doesn't exist. 
> @ellis is working on this issue in [0] (for static vars) and [1] (for 
> imported declarations).
> (2) the same entities (static local vars, typedefs, etc) that should be 
> scoped within a lexical block have a subprogram scope (in debug metadata) and 
> parent DIE (in DWARF) instead. This is the issue I'm trying to fix in this 
> patch, but for static variables only.
>
> As a side effect, this patch fixes the issue with inlined functions for 
> static vars (1) as well. But it seems the issues are not related and can be 
> fixed separately.
> And as now I've realized that static locals is not the only problem, this 
> patch should implement a more generic solution to cover other entities. So, 
> please, consider it as a WIP.

Hey @krisb I was under the impression that this patch would fix the static 
variable bug. Should I wait to see what this patch fixes before working on [0] 
and [1]?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109703/new/

https://reviews.llvm.org/D109703

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


[PATCH] D104088: Add clang frontend flags for MIP

2021-06-10 Thread Ellis Hoag via Phabricator via cfe-commits
ellis created this revision.
Herald added subscribers: dang, phosek, mgorny, emaste.
Herald added a reviewer: alexshap.
Herald added a reviewer: rupprecht.
Herald added a reviewer: jhenderson.
ellis requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, MaskRay.
Herald added projects: clang, LLVM.

Add clang frontend flags for machine profiles.

- `-fmachine-profile-generate`
  - Produce an instrumented binary
- `-fmachine-profile-function-coverage`
  - Only profile function coverage
- `-fmachine-profile-block-coverage`
  - Profile basic block coverage
- `-fmachine-profile-link-unit-name=`
  - Specify a name to identify the current link unit
- `-fno-machine-profile-runtime`
  - Do not link the MIP runtime
- `-fno-machine-profile-dump`
  - Do not dump the raw profile data when the program exits
- `-fmachine-profile-selected-function-group=`, 
`-fmachine-profile-function-group-count=`
  - Only instrument group `i` of `N` total groups of functions
- `-fmachine-profile-use=`
  - Use the provided profile for optimization


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104088

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Driver/ToolChains/Darwin.h
  clang/lib/Driver/ToolChains/DragonFly.cpp
  clang/lib/Driver/ToolChains/FreeBSD.cpp
  clang/lib/Driver/ToolChains/Fuchsia.cpp
  clang/lib/Driver/ToolChains/Fuchsia.h
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/lib/Driver/ToolChains/Linux.h
  clang/lib/Driver/ToolChains/NetBSD.cpp
  clang/lib/Driver/ToolChains/Solaris.cpp
  clang/test/CMakeLists.txt
  clang/test/Driver/clang-mip-flags.c
  llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp

Index: llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
===
--- llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
+++ llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
@@ -55,7 +55,8 @@
 
 static bool isDebugSection(const SectionBase &Sec) {
   return StringRef(Sec.Name).startswith(".debug") ||
- StringRef(Sec.Name).startswith(".zdebug") || Sec.Name == ".gdb_index";
+ StringRef(Sec.Name).startswith(".zdebug") ||
+ Sec.Name == ".gdb_index" || Sec.Name == "__llvm_mipmap";
 }
 
 static bool isDWOSection(const SectionBase &Sec) {
Index: clang/test/Driver/clang-mip-flags.c
===
--- /dev/null
+++ clang/test/Driver/clang-mip-flags.c
@@ -0,0 +1,44 @@
+// REQUIRES: clang-driver
+
+// RUN: %clang -### -fmachine-profile-use=/path/to/profile.mip %s 2>&1 | FileCheck %s --check-prefix USE
+// USE: "-cc1"
+// USE-SAME: "-mllvm" "-machine-profile-use=/path/to/profile.mip"
+// USE-SAME: "-mllvm" "-link-unit-name=a.out"
+
+// RUN: %clang -### -fmachine-profile-use=/path/to/profile.mip -o my-executable %s 2>&1 | FileCheck %s --check-prefix USE-OUTPUT
+// RUN: %clang -### -fmachine-profile-use=/path/to/profile.mip -fmachine-profile-link-unit-name=my-executable %s 2>&1 | FileCheck %s --check-prefix USE-OUTPUT
+// USE-OUTPUT: "-cc1"
+// USE-OUTPUT-SAME: "-mllvm" "-link-unit-name=my-executable"
+
+// RUN: %clang -### -fmachine-profile-generate %s 2>&1 | FileCheck %s --check-prefix GEN
+// RUN: %clang -### -fno-machine-profile-generate -fmachine-profile-generate %s 2>&1 | FileCheck %s --check-prefix GEN
+// GEN: "-cc1"
+// GEN-SAME: "-mllvm" "-enable-machine-instrumentation"
+// GEN-SAME: "-mllvm" "-link-unit-name=a.out"
+
+// RUN: %clang -### %s 2>&1 | FileCheck %s --check-prefix NOGEN
+// RUN: %clang -### -fno-machine-profile-generate %s 2>&1 | FileCheck %s --check-prefix NOGEN
+// RUN: %clang -### -fmachine-profile-generate -fno-machine-profile-generate %s 2>&1 | FileCheck %s --check-prefix NOGEN
+// NOGEN-NOT: "-enable-machine-instrumentation"
+
+// RUN: %clang -### -fmachine-profile-generate -fmachine-profile-function-coverage %s 2>&1 | FileCheck %s --check-prefix FUNCCOV
+// FUNCCOV: "-cc1"
+// FUNCCOV-SAME: "-mllvm" "-enable-machine-function-coverage"
+
+// RUN: %clang -### -fmachine-profile-generate -fmachine-profile-block-coverage %s 2>&1 | FileCheck %s --check-prefix BLOCKCOV
+// BLOCKCOV: "-cc1"
+// BLOCKCOV-SAME: "-mllvm" "-enable-machine-block-coverage"
+
+// RUN: %clang -### -fmachine-profile-generate %s 2>&1 | FileCheck %s --check-prefix FULL
+// RUN: %clang -### -fmachine-profile-generate -fmachine-profile-call-graph %s 2>&1 | FileCheck %s --check-prefix FULL
+// FULL: "-cc1"
+// FULL-SAME: "-mllvm" "-enable-machine-call-graph"
+
+// RUN: %clang -### -fmachine-profile-generate -fmachine-profile-runtime-buffer=1024 %s 2>&1 | FileCheck %s --check-prefix RUNTIMEBUF
+// RUNTIMEBUF: "-cc1"
+// RUNTIMEBUF-SAME: "-mllvm" "-machine-profile-runtime-buffer=1024"
+
+// RUN: %clang -### -fmachine-profile-generate -fmachine-profile-funct

[PATCH] D104088: Add clang frontend flags for MIP

2021-06-11 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 351604.
ellis added a comment.

Move llvm-strip logic into its own commit


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104088/new/

https://reviews.llvm.org/D104088

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Driver/ToolChains/Darwin.h
  clang/lib/Driver/ToolChains/DragonFly.cpp
  clang/lib/Driver/ToolChains/FreeBSD.cpp
  clang/lib/Driver/ToolChains/Fuchsia.cpp
  clang/lib/Driver/ToolChains/Fuchsia.h
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/lib/Driver/ToolChains/Linux.h
  clang/lib/Driver/ToolChains/NetBSD.cpp
  clang/lib/Driver/ToolChains/Solaris.cpp
  clang/test/CMakeLists.txt
  clang/test/Driver/clang-mip-flags.c

Index: clang/test/Driver/clang-mip-flags.c
===
--- /dev/null
+++ clang/test/Driver/clang-mip-flags.c
@@ -0,0 +1,44 @@
+// REQUIRES: clang-driver
+
+// RUN: %clang -### -fmachine-profile-use=/path/to/profile.mip %s 2>&1 | FileCheck %s --check-prefix USE
+// USE: "-cc1"
+// USE-SAME: "-mllvm" "-machine-profile-use=/path/to/profile.mip"
+// USE-SAME: "-mllvm" "-link-unit-name=a.out"
+
+// RUN: %clang -### -fmachine-profile-use=/path/to/profile.mip -o my-executable %s 2>&1 | FileCheck %s --check-prefix USE-OUTPUT
+// RUN: %clang -### -fmachine-profile-use=/path/to/profile.mip -fmachine-profile-link-unit-name=my-executable %s 2>&1 | FileCheck %s --check-prefix USE-OUTPUT
+// USE-OUTPUT: "-cc1"
+// USE-OUTPUT-SAME: "-mllvm" "-link-unit-name=my-executable"
+
+// RUN: %clang -### -fmachine-profile-generate %s 2>&1 | FileCheck %s --check-prefix GEN
+// RUN: %clang -### -fno-machine-profile-generate -fmachine-profile-generate %s 2>&1 | FileCheck %s --check-prefix GEN
+// GEN: "-cc1"
+// GEN-SAME: "-mllvm" "-enable-machine-instrumentation"
+// GEN-SAME: "-mllvm" "-link-unit-name=a.out"
+
+// RUN: %clang -### %s 2>&1 | FileCheck %s --check-prefix NOGEN
+// RUN: %clang -### -fno-machine-profile-generate %s 2>&1 | FileCheck %s --check-prefix NOGEN
+// RUN: %clang -### -fmachine-profile-generate -fno-machine-profile-generate %s 2>&1 | FileCheck %s --check-prefix NOGEN
+// NOGEN-NOT: "-enable-machine-instrumentation"
+
+// RUN: %clang -### -fmachine-profile-generate -fmachine-profile-function-coverage %s 2>&1 | FileCheck %s --check-prefix FUNCCOV
+// FUNCCOV: "-cc1"
+// FUNCCOV-SAME: "-mllvm" "-enable-machine-function-coverage"
+
+// RUN: %clang -### -fmachine-profile-generate -fmachine-profile-block-coverage %s 2>&1 | FileCheck %s --check-prefix BLOCKCOV
+// BLOCKCOV: "-cc1"
+// BLOCKCOV-SAME: "-mllvm" "-enable-machine-block-coverage"
+
+// RUN: %clang -### -fmachine-profile-generate %s 2>&1 | FileCheck %s --check-prefix FULL
+// RUN: %clang -### -fmachine-profile-generate -fmachine-profile-call-graph %s 2>&1 | FileCheck %s --check-prefix FULL
+// FULL: "-cc1"
+// FULL-SAME: "-mllvm" "-enable-machine-call-graph"
+
+// RUN: %clang -### -fmachine-profile-generate -fmachine-profile-runtime-buffer=1024 %s 2>&1 | FileCheck %s --check-prefix RUNTIMEBUF
+// RUNTIMEBUF: "-cc1"
+// RUNTIMEBUF-SAME: "-mllvm" "-machine-profile-runtime-buffer=1024"
+
+// RUN: %clang -### -fmachine-profile-generate -fmachine-profile-function-group-count=22 -fmachine-profile-selected-function-group=11 %s 2>&1 | FileCheck %s --check-prefix GEN-GROUPS
+// GEN-GROUPS: "-cc1"
+// GEN-GROUPS-SAME: "-mllvm" "-machine-profile-function-group-count=22"
+// GEN-GROUPS-SAME: "-mllvm" "-machine-profile-selected-function-group=11"
Index: clang/test/CMakeLists.txt
===
--- clang/test/CMakeLists.txt
+++ clang/test/CMakeLists.txt
@@ -118,6 +118,7 @@
 llvm-lto2
 llvm-modextract
 llvm-nm
+llvm-mipdata
 llvm-objcopy
 llvm-objdump
 llvm-profdata
Index: clang/lib/Driver/ToolChains/Solaris.cpp
===
--- clang/lib/Driver/ToolChains/Solaris.cpp
+++ clang/lib/Driver/ToolChains/Solaris.cpp
@@ -149,6 +149,7 @@
   CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crtn.o")));
 
   getToolChain().addProfileRTLibs(Args, CmdArgs);
+  getToolChain().addMachineProfileRTLibs(Args, CmdArgs);
 
   const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath());
   C.addCommand(std::make_unique(JA, *this, ResponseFileSupport::None(),
Index: clang/lib/Driver/ToolChains/NetBSD.cpp
===
--- clang/lib/Driver/ToolChains/NetBSD.cpp
+++ clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -337,6 +337,7 @@
   }
 
   ToolChain.addProfileRTLibs(Args, CmdArgs);
+  ToolChain.addMachineProfileRTLibs(Args, CmdArgs);
 
   const char *Exec = Args.MakeArgString(ToolChain.Get

[PATCH] D104088: Add clang frontend flags for MIP

2021-06-14 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 352007.
ellis added a comment.

MIP does not support windows


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104088/new/

https://reviews.llvm.org/D104088

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Driver/ToolChains/Darwin.h
  clang/lib/Driver/ToolChains/DragonFly.cpp
  clang/lib/Driver/ToolChains/FreeBSD.cpp
  clang/lib/Driver/ToolChains/Fuchsia.cpp
  clang/lib/Driver/ToolChains/Fuchsia.h
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/lib/Driver/ToolChains/Linux.h
  clang/lib/Driver/ToolChains/NetBSD.cpp
  clang/lib/Driver/ToolChains/Solaris.cpp
  clang/test/CMakeLists.txt
  clang/test/Driver/clang-mip-flags.c

Index: clang/test/Driver/clang-mip-flags.c
===
--- /dev/null
+++ clang/test/Driver/clang-mip-flags.c
@@ -0,0 +1,45 @@
+// REQUIRES: clang-driver
+// UNSUPPORTED: windows-msvc
+
+// RUN: %clang -### -fmachine-profile-use=/path/to/profile.mip %s 2>&1 | FileCheck %s --check-prefix USE
+// USE: "-cc1"
+// USE-SAME: "-mllvm" "-machine-profile-use=/path/to/profile.mip"
+// USE-SAME: "-mllvm" "-link-unit-name=a.out"
+
+// RUN: %clang -### -fmachine-profile-use=/path/to/profile.mip -o my-executable %s 2>&1 | FileCheck %s --check-prefix USE-OUTPUT
+// RUN: %clang -### -fmachine-profile-use=/path/to/profile.mip -fmachine-profile-link-unit-name=my-executable %s 2>&1 | FileCheck %s --check-prefix USE-OUTPUT
+// USE-OUTPUT: "-cc1"
+// USE-OUTPUT-SAME: "-mllvm" "-link-unit-name=my-executable"
+
+// RUN: %clang -### -fmachine-profile-generate %s 2>&1 | FileCheck %s --check-prefix GEN
+// RUN: %clang -### -fno-machine-profile-generate -fmachine-profile-generate %s 2>&1 | FileCheck %s --check-prefix GEN
+// GEN: "-cc1"
+// GEN-SAME: "-mllvm" "-enable-machine-instrumentation"
+// GEN-SAME: "-mllvm" "-link-unit-name=a.out"
+
+// RUN: %clang -### %s 2>&1 | FileCheck %s --check-prefix NOGEN
+// RUN: %clang -### -fno-machine-profile-generate %s 2>&1 | FileCheck %s --check-prefix NOGEN
+// RUN: %clang -### -fmachine-profile-generate -fno-machine-profile-generate %s 2>&1 | FileCheck %s --check-prefix NOGEN
+// NOGEN-NOT: "-enable-machine-instrumentation"
+
+// RUN: %clang -### -fmachine-profile-generate -fmachine-profile-function-coverage %s 2>&1 | FileCheck %s --check-prefix FUNCCOV
+// FUNCCOV: "-cc1"
+// FUNCCOV-SAME: "-mllvm" "-enable-machine-function-coverage"
+
+// RUN: %clang -### -fmachine-profile-generate -fmachine-profile-block-coverage %s 2>&1 | FileCheck %s --check-prefix BLOCKCOV
+// BLOCKCOV: "-cc1"
+// BLOCKCOV-SAME: "-mllvm" "-enable-machine-block-coverage"
+
+// RUN: %clang -### -fmachine-profile-generate %s 2>&1 | FileCheck %s --check-prefix FULL
+// RUN: %clang -### -fmachine-profile-generate -fmachine-profile-call-graph %s 2>&1 | FileCheck %s --check-prefix FULL
+// FULL: "-cc1"
+// FULL-SAME: "-mllvm" "-enable-machine-call-graph"
+
+// RUN: %clang -### -fmachine-profile-generate -fmachine-profile-runtime-buffer=1024 %s 2>&1 | FileCheck %s --check-prefix RUNTIMEBUF
+// RUNTIMEBUF: "-cc1"
+// RUNTIMEBUF-SAME: "-mllvm" "-machine-profile-runtime-buffer=1024"
+
+// RUN: %clang -### -fmachine-profile-generate -fmachine-profile-function-group-count=22 -fmachine-profile-selected-function-group=11 %s 2>&1 | FileCheck %s --check-prefix GEN-GROUPS
+// GEN-GROUPS: "-cc1"
+// GEN-GROUPS-SAME: "-mllvm" "-machine-profile-function-group-count=22"
+// GEN-GROUPS-SAME: "-mllvm" "-machine-profile-selected-function-group=11"
Index: clang/test/CMakeLists.txt
===
--- clang/test/CMakeLists.txt
+++ clang/test/CMakeLists.txt
@@ -118,6 +118,7 @@
 llvm-lto2
 llvm-modextract
 llvm-nm
+llvm-mipdata
 llvm-objcopy
 llvm-objdump
 llvm-profdata
Index: clang/lib/Driver/ToolChains/Solaris.cpp
===
--- clang/lib/Driver/ToolChains/Solaris.cpp
+++ clang/lib/Driver/ToolChains/Solaris.cpp
@@ -149,6 +149,7 @@
   CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crtn.o")));
 
   getToolChain().addProfileRTLibs(Args, CmdArgs);
+  getToolChain().addMachineProfileRTLibs(Args, CmdArgs);
 
   const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath());
   C.addCommand(std::make_unique(JA, *this, ResponseFileSupport::None(),
Index: clang/lib/Driver/ToolChains/NetBSD.cpp
===
--- clang/lib/Driver/ToolChains/NetBSD.cpp
+++ clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -337,6 +337,7 @@
   }
 
   ToolChain.addProfileRTLibs(Args, CmdArgs);
+  ToolChain.addMachineProfileRTLibs(Args, CmdArgs);
 
   const char *Exec = Args.MakeArgStr

[PATCH] D104088: Add clang frontend flags for MIP

2021-06-22 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 353705.
ellis added a comment.

Correctly link the runtime symbol for Mach-O.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104088/new/

https://reviews.llvm.org/D104088

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Driver/ToolChains/Darwin.h
  clang/lib/Driver/ToolChains/DragonFly.cpp
  clang/lib/Driver/ToolChains/FreeBSD.cpp
  clang/lib/Driver/ToolChains/Fuchsia.cpp
  clang/lib/Driver/ToolChains/Fuchsia.h
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/lib/Driver/ToolChains/Linux.h
  clang/lib/Driver/ToolChains/NetBSD.cpp
  clang/lib/Driver/ToolChains/Solaris.cpp
  clang/test/CMakeLists.txt
  clang/test/Driver/clang-mip-flags.c

Index: clang/test/Driver/clang-mip-flags.c
===
--- /dev/null
+++ clang/test/Driver/clang-mip-flags.c
@@ -0,0 +1,45 @@
+// REQUIRES: clang-driver
+// UNSUPPORTED: windows-msvc
+
+// RUN: %clang -### -fmachine-profile-use=/path/to/profile.mip %s 2>&1 | FileCheck %s --check-prefix USE
+// USE: "-cc1"
+// USE-SAME: "-mllvm" "-machine-profile-use=/path/to/profile.mip"
+// USE-SAME: "-mllvm" "-link-unit-name=a.out"
+
+// RUN: %clang -### -fmachine-profile-use=/path/to/profile.mip -o my-executable %s 2>&1 | FileCheck %s --check-prefix USE-OUTPUT
+// RUN: %clang -### -fmachine-profile-use=/path/to/profile.mip -fmachine-profile-link-unit-name=my-executable %s 2>&1 | FileCheck %s --check-prefix USE-OUTPUT
+// USE-OUTPUT: "-cc1"
+// USE-OUTPUT-SAME: "-mllvm" "-link-unit-name=my-executable"
+
+// RUN: %clang -### -fmachine-profile-generate %s 2>&1 | FileCheck %s --check-prefix GEN
+// RUN: %clang -### -fno-machine-profile-generate -fmachine-profile-generate %s 2>&1 | FileCheck %s --check-prefix GEN
+// GEN: "-cc1"
+// GEN-SAME: "-mllvm" "-enable-machine-instrumentation"
+// GEN-SAME: "-mllvm" "-link-unit-name=a.out"
+
+// RUN: %clang -### %s 2>&1 | FileCheck %s --check-prefix NOGEN
+// RUN: %clang -### -fno-machine-profile-generate %s 2>&1 | FileCheck %s --check-prefix NOGEN
+// RUN: %clang -### -fmachine-profile-generate -fno-machine-profile-generate %s 2>&1 | FileCheck %s --check-prefix NOGEN
+// NOGEN-NOT: "-enable-machine-instrumentation"
+
+// RUN: %clang -### -fmachine-profile-generate -fmachine-profile-function-coverage %s 2>&1 | FileCheck %s --check-prefix FUNCCOV
+// FUNCCOV: "-cc1"
+// FUNCCOV-SAME: "-mllvm" "-enable-machine-function-coverage"
+
+// RUN: %clang -### -fmachine-profile-generate -fmachine-profile-block-coverage %s 2>&1 | FileCheck %s --check-prefix BLOCKCOV
+// BLOCKCOV: "-cc1"
+// BLOCKCOV-SAME: "-mllvm" "-enable-machine-block-coverage"
+
+// RUN: %clang -### -fmachine-profile-generate %s 2>&1 | FileCheck %s --check-prefix FULL
+// RUN: %clang -### -fmachine-profile-generate -fmachine-profile-call-graph %s 2>&1 | FileCheck %s --check-prefix FULL
+// FULL: "-cc1"
+// FULL-SAME: "-mllvm" "-enable-machine-call-graph"
+
+// RUN: %clang -### -fmachine-profile-generate -fmachine-profile-runtime-buffer=1024 %s 2>&1 | FileCheck %s --check-prefix RUNTIMEBUF
+// RUNTIMEBUF: "-cc1"
+// RUNTIMEBUF-SAME: "-mllvm" "-machine-profile-runtime-buffer=1024"
+
+// RUN: %clang -### -fmachine-profile-generate -fmachine-profile-function-group-count=22 -fmachine-profile-selected-function-group=11 %s 2>&1 | FileCheck %s --check-prefix GEN-GROUPS
+// GEN-GROUPS: "-cc1"
+// GEN-GROUPS-SAME: "-mllvm" "-machine-profile-function-group-count=22"
+// GEN-GROUPS-SAME: "-mllvm" "-machine-profile-selected-function-group=11"
Index: clang/test/CMakeLists.txt
===
--- clang/test/CMakeLists.txt
+++ clang/test/CMakeLists.txt
@@ -118,6 +118,7 @@
 llvm-lto2
 llvm-modextract
 llvm-nm
+llvm-mipdata
 llvm-objcopy
 llvm-objdump
 llvm-profdata
Index: clang/lib/Driver/ToolChains/Solaris.cpp
===
--- clang/lib/Driver/ToolChains/Solaris.cpp
+++ clang/lib/Driver/ToolChains/Solaris.cpp
@@ -149,6 +149,7 @@
   CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crtn.o")));
 
   getToolChain().addProfileRTLibs(Args, CmdArgs);
+  getToolChain().addMachineProfileRTLibs(Args, CmdArgs);
 
   const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath());
   C.addCommand(std::make_unique(JA, *this, ResponseFileSupport::None(),
Index: clang/lib/Driver/ToolChains/NetBSD.cpp
===
--- clang/lib/Driver/ToolChains/NetBSD.cpp
+++ clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -337,6 +337,7 @@
   }
 
   ToolChain.addProfileRTLibs(Args, CmdArgs);
+  ToolChain.addMachineProfileRTLibs(Args, CmdArgs);
 
   const char *Exec 

[PATCH] D107024: [DIBuilder] Do not replace empty enum types

2021-08-04 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added a comment.

In D107024#2917202 , @aprantl wrote:

> I think that looks fine — I wonder if we should change the IR pretty printer 
> to display empty arrays inline as `elements: !{}`, too.

I think that's a good idea, but it would require changing lots of tests.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107024/new/

https://reviews.llvm.org/D107024

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


[PATCH] D107024: [DIBuilder] Do not replace empty enum types

2021-08-10 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added a comment.

@aprantl @dblaikie Can I get a review soon to avoid merge conflicts on these 
tests?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107024/new/

https://reviews.llvm.org/D107024

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


[PATCH] D104088: Add clang frontend flags for MIP

2021-06-28 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 355066.
ellis added a comment.

Add min instruction count frontend flag.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104088/new/

https://reviews.llvm.org/D104088

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Driver/ToolChains/Darwin.h
  clang/lib/Driver/ToolChains/DragonFly.cpp
  clang/lib/Driver/ToolChains/FreeBSD.cpp
  clang/lib/Driver/ToolChains/Fuchsia.cpp
  clang/lib/Driver/ToolChains/Fuchsia.h
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/lib/Driver/ToolChains/Linux.h
  clang/lib/Driver/ToolChains/NetBSD.cpp
  clang/lib/Driver/ToolChains/Solaris.cpp
  clang/test/CMakeLists.txt
  clang/test/Driver/clang-mip-flags.c

Index: clang/test/Driver/clang-mip-flags.c
===
--- /dev/null
+++ clang/test/Driver/clang-mip-flags.c
@@ -0,0 +1,49 @@
+// REQUIRES: clang-driver
+// UNSUPPORTED: windows-msvc
+
+// RUN: %clang -### -fmachine-profile-use=/path/to/profile.mip %s 2>&1 | FileCheck %s --check-prefix USE
+// USE: "-cc1"
+// USE-SAME: "-mllvm" "-machine-profile-use=/path/to/profile.mip"
+// USE-SAME: "-mllvm" "-link-unit-name=a.out"
+
+// RUN: %clang -### -fmachine-profile-use=/path/to/profile.mip -o my-executable %s 2>&1 | FileCheck %s --check-prefix USE-OUTPUT
+// RUN: %clang -### -fmachine-profile-use=/path/to/profile.mip -fmachine-profile-link-unit-name=my-executable %s 2>&1 | FileCheck %s --check-prefix USE-OUTPUT
+// USE-OUTPUT: "-cc1"
+// USE-OUTPUT-SAME: "-mllvm" "-link-unit-name=my-executable"
+
+// RUN: %clang -### -fmachine-profile-generate %s 2>&1 | FileCheck %s --check-prefix GEN
+// RUN: %clang -### -fno-machine-profile-generate -fmachine-profile-generate %s 2>&1 | FileCheck %s --check-prefix GEN
+// GEN: "-cc1"
+// GEN-SAME: "-mllvm" "-enable-machine-instrumentation"
+// GEN-SAME: "-mllvm" "-link-unit-name=a.out"
+
+// RUN: %clang -### %s 2>&1 | FileCheck %s --check-prefix NOGEN
+// RUN: %clang -### -fno-machine-profile-generate %s 2>&1 | FileCheck %s --check-prefix NOGEN
+// RUN: %clang -### -fmachine-profile-generate -fno-machine-profile-generate %s 2>&1 | FileCheck %s --check-prefix NOGEN
+// NOGEN-NOT: "-enable-machine-instrumentation"
+
+// RUN: %clang -### -fmachine-profile-generate -fmachine-profile-function-coverage %s 2>&1 | FileCheck %s --check-prefix FUNCCOV
+// FUNCCOV: "-cc1"
+// FUNCCOV-SAME: "-mllvm" "-enable-machine-function-coverage"
+
+// RUN: %clang -### -fmachine-profile-generate -fmachine-profile-block-coverage %s 2>&1 | FileCheck %s --check-prefix BLOCKCOV
+// BLOCKCOV: "-cc1"
+// BLOCKCOV-SAME: "-mllvm" "-enable-machine-block-coverage"
+
+// RUN: %clang -### -fmachine-profile-generate %s 2>&1 | FileCheck %s --check-prefix FULL
+// RUN: %clang -### -fmachine-profile-generate -fmachine-profile-call-graph %s 2>&1 | FileCheck %s --check-prefix FULL
+// FULL: "-cc1"
+// FULL-SAME: "-mllvm" "-enable-machine-call-graph"
+
+// RUN: %clang -### -fmachine-profile-generate -fmachine-profile-runtime-buffer=1024 %s 2>&1 | FileCheck %s --check-prefix RUNTIMEBUF
+// RUNTIMEBUF: "-cc1"
+// RUNTIMEBUF-SAME: "-mllvm" "-machine-profile-runtime-buffer=1024"
+
+// RUN: %clang -### -fmachine-profile-generate -fmachine-profile-function-group-count=22 -fmachine-profile-selected-function-group=11 %s 2>&1 | FileCheck %s --check-prefix GEN-GROUPS
+// GEN-GROUPS: "-cc1"
+// GEN-GROUPS-SAME: "-mllvm" "-machine-profile-function-group-count=22"
+// GEN-GROUPS-SAME: "-mllvm" "-machine-profile-selected-function-group=11"
+
+// RUN: %clang -### -fmachine-profile-generate -fmachine-profile-min-instruction-count=50 %s 2>&1 | FileCheck %s --check-prefix MIN-INSTR
+// MIN-INSTR: "-cc1"
+// MIN-INSTR-SAME: "-mllvm" "-machine-profile-min-instruction-count=50"
Index: clang/test/CMakeLists.txt
===
--- clang/test/CMakeLists.txt
+++ clang/test/CMakeLists.txt
@@ -118,6 +118,7 @@
 llvm-lto2
 llvm-modextract
 llvm-nm
+llvm-mipdata
 llvm-objcopy
 llvm-objdump
 llvm-profdata
Index: clang/lib/Driver/ToolChains/Solaris.cpp
===
--- clang/lib/Driver/ToolChains/Solaris.cpp
+++ clang/lib/Driver/ToolChains/Solaris.cpp
@@ -149,6 +149,7 @@
   CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crtn.o")));
 
   getToolChain().addProfileRTLibs(Args, CmdArgs);
+  getToolChain().addMachineProfileRTLibs(Args, CmdArgs);
 
   const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath());
   C.addCommand(std::make_unique(JA, *this, ResponseFileSupport::None(),
Index: clang/lib/Driver/ToolChains/NetBSD.cpp
===
---

[PATCH] D114268: [InstrProf] Use i32 for GEP index from lowering llvm.instrprof.increment

2021-11-19 Thread Ellis Hoag via Phabricator via cfe-commits
ellis created this revision.
Herald added subscribers: wenlei, arphaman, hiraditya.
ellis updated this revision to Diff 388564.
ellis added a comment.
ellis edited the summary of this revision.
ellis added a reviewer: MaskRay.
ellis retitled this revision from "[InstrProf] Use i32 for GEP index" to 
"[InstrProf] Use i32 for GEP index from lowering llvm.instrprof.increment".
ellis published this revision for review.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Run `clang-format`.


The `llvm.instrprof.increment` intrinsic uses `i32` for the index. We should 
use this same type for the index into the GEP instructions.

Add names to pgo registers for clarity.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114268

Files:
  clang/test/CodeGen/profile-filter.c
  clang/test/Profile/branch-logical-mixed.cpp
  clang/test/Profile/c-captured.c
  clang/test/Profile/c-general.c
  clang/test/Profile/c-ternary.c
  clang/test/Profile/cxx-class.cpp
  clang/test/Profile/cxx-lambda.cpp
  clang/test/Profile/cxx-rangefor.cpp
  clang/test/Profile/cxx-stmt-initializers.cpp
  clang/test/Profile/cxx-templates.cpp
  clang/test/Profile/cxx-throws.cpp
  clang/test/Profile/objc-general.m
  llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
  llvm/test/Instrumentation/InstrProfiling/atomic-updates.ll
  llvm/test/Instrumentation/InstrProfiling/runtime-counter-relocation.ll
  llvm/test/Transforms/PGOProfile/counter_promo_exit_catchswitch.ll
  llvm/test/Transforms/PGOProfile/instr_entry_bb.ll

Index: llvm/test/Transforms/PGOProfile/instr_entry_bb.ll
===
--- llvm/test/Transforms/PGOProfile/instr_entry_bb.ll
+++ llvm/test/Transforms/PGOProfile/instr_entry_bb.ll
@@ -18,7 +18,7 @@
 ; GEN: entry:
 ; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @__profn_test_br_2, i32 0, i32 0), i64 {{[0-9]+}}, i32 2, i32 0)
 ; GENA: entry:
-; GENA: %{{[0-9+]}} = atomicrmw add i64* getelementptr inbounds ([2 x i64], [2 x i64]* @__profc_test_br_2, i64 0, i64 0), i64 1 monotonic
+; GENA: %{{[0-9+]}} = atomicrmw add i64* getelementptr inbounds ([2 x i64], [2 x i64]* @__profc_test_br_2, i32 0, i32 0), i64 1 monotonic
 ; USE: br i1 %cmp, label %if.then, label %if.else
 ; USE-SAME: !prof ![[BW_ENTRY:[0-9]+]]
 ; USE: ![[BW_ENTRY]] = !{!"branch_weights", i32 0, i32 1}
@@ -35,9 +35,9 @@
 ; GEN: if.else:
 ; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @__profn_test_br_2, i32 0, i32 0), i64 {{[0-9]+}}, i32 2, i32 1)
 ; GENA: if.else:
-; GENA:  %pgocount = load i64, i64* getelementptr inbounds ([2 x i64], [2 x i64]* @__profc_test_br_2, i64 0, i64 1), align 8
+; GENA:  %pgocount = load i64, i64* getelementptr inbounds ([2 x i64], [2 x i64]* @__profc_test_br_2, i32 0, i32 1), align 8
 ; GENA:  [[V:%[0-9]*]] = add i64 %pgocount, 1
-; GENA:  store i64 [[V]], i64* getelementptr inbounds ([2 x i64], [2 x i64]* @__profc_test_br_2, i64 0, i64 1), align 8
+; GENA:  store i64 [[V]], i64* getelementptr inbounds ([2 x i64], [2 x i64]* @__profc_test_br_2, i32 0, i32 1), align 8
   %sub = sub nsw i32 %i, 2
   br label %if.end
 
Index: llvm/test/Transforms/PGOProfile/counter_promo_exit_catchswitch.ll
===
--- llvm/test/Transforms/PGOProfile/counter_promo_exit_catchswitch.ll
+++ llvm/test/Transforms/PGOProfile/counter_promo_exit_catchswitch.ll
@@ -38,11 +38,11 @@
 
 for.body: ; preds = %for.cond
 ; CHECK: for.body:
-; NOTENTRY: %pgocount1 = load i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i64 0, i64 0)
-; TENTRY: %pgocount1 = load i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i64 0, i64 1)
+; NOTENTRY: %pgocount1 = load i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i32 0, i32 0)
+; TENTRY: %pgocount1 = load i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i32 0, i32 1)
 ; CHECK: %1 = add i64 %pgocount1, 1
-; NOTENTRY: store i64 %1, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i64 0, i64 0)
-; ENTRY: store i64 %1, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i64 0, i64 1)
+; NOTENTRY: store i64 %1, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i32 0, i32 0)
+; ENTRY: store i64 %1, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i32 0, i32 1)
   %idxprom = zext i32 %i.0 to i64
   %arrayidx = getelementptr inbounds [200 x i8], [200 x i8]* @"?buffer@@3PADA", i64 0, i64 %idxprom
   %0 = load i8, i8* %arrayidx, align 1
@@ -55,11 +55,11 @@
 
 for.inc:  ; preds = %if.end
 ; CHECK: for.inc:
-; NOTENTRY: %pgocount2 = load i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_

[PATCH] D114268: [InstrProf] Use i32 for GEP index from lowering llvm.instrprof.increment

2021-11-19 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added a comment.

In D114268#3143976 , @MaskRay wrote:

>> Add names to pgo registers for clarity.
>
> This may increase memory usage, especially for large LTO applications. Unless 
> this is very helpful I might omit it.

I'll omit it. Thanks for the quick review!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114268/new/

https://reviews.llvm.org/D114268

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


[PATCH] D114268: [InstrProf] Use i32 for GEP index from lowering llvm.instrprof.increment

2021-11-19 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 388652.
ellis added a comment.

Remove register names


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114268/new/

https://reviews.llvm.org/D114268

Files:
  clang/test/CodeGen/profile-filter.c
  clang/test/Profile/branch-logical-mixed.cpp
  clang/test/Profile/c-captured.c
  clang/test/Profile/c-general.c
  clang/test/Profile/c-ternary.c
  clang/test/Profile/cxx-class.cpp
  clang/test/Profile/cxx-lambda.cpp
  clang/test/Profile/cxx-rangefor.cpp
  clang/test/Profile/cxx-stmt-initializers.cpp
  clang/test/Profile/cxx-templates.cpp
  clang/test/Profile/cxx-throws.cpp
  clang/test/Profile/objc-general.m
  llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
  llvm/test/Instrumentation/InstrProfiling/atomic-updates.ll
  llvm/test/Instrumentation/InstrProfiling/runtime-counter-relocation.ll
  llvm/test/Transforms/PGOProfile/counter_promo_exit_catchswitch.ll
  llvm/test/Transforms/PGOProfile/instr_entry_bb.ll

Index: llvm/test/Transforms/PGOProfile/instr_entry_bb.ll
===
--- llvm/test/Transforms/PGOProfile/instr_entry_bb.ll
+++ llvm/test/Transforms/PGOProfile/instr_entry_bb.ll
@@ -18,7 +18,7 @@
 ; GEN: entry:
 ; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @__profn_test_br_2, i32 0, i32 0), i64 {{[0-9]+}}, i32 2, i32 0)
 ; GENA: entry:
-; GENA: %{{[0-9+]}} = atomicrmw add i64* getelementptr inbounds ([2 x i64], [2 x i64]* @__profc_test_br_2, i64 0, i64 0), i64 1 monotonic
+; GENA: %{{[0-9+]}} = atomicrmw add i64* getelementptr inbounds ([2 x i64], [2 x i64]* @__profc_test_br_2, i32 0, i32 0), i64 1 monotonic
 ; USE: br i1 %cmp, label %if.then, label %if.else
 ; USE-SAME: !prof ![[BW_ENTRY:[0-9]+]]
 ; USE: ![[BW_ENTRY]] = !{!"branch_weights", i32 0, i32 1}
@@ -35,9 +35,9 @@
 ; GEN: if.else:
 ; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @__profn_test_br_2, i32 0, i32 0), i64 {{[0-9]+}}, i32 2, i32 1)
 ; GENA: if.else:
-; GENA:  %pgocount = load i64, i64* getelementptr inbounds ([2 x i64], [2 x i64]* @__profc_test_br_2, i64 0, i64 1), align 8
+; GENA:  %pgocount = load i64, i64* getelementptr inbounds ([2 x i64], [2 x i64]* @__profc_test_br_2, i32 0, i32 1), align 8
 ; GENA:  [[V:%[0-9]*]] = add i64 %pgocount, 1
-; GENA:  store i64 [[V]], i64* getelementptr inbounds ([2 x i64], [2 x i64]* @__profc_test_br_2, i64 0, i64 1), align 8
+; GENA:  store i64 [[V]], i64* getelementptr inbounds ([2 x i64], [2 x i64]* @__profc_test_br_2, i32 0, i32 1), align 8
   %sub = sub nsw i32 %i, 2
   br label %if.end
 
Index: llvm/test/Transforms/PGOProfile/counter_promo_exit_catchswitch.ll
===
--- llvm/test/Transforms/PGOProfile/counter_promo_exit_catchswitch.ll
+++ llvm/test/Transforms/PGOProfile/counter_promo_exit_catchswitch.ll
@@ -38,11 +38,11 @@
 
 for.body: ; preds = %for.cond
 ; CHECK: for.body:
-; NOTENTRY: %pgocount1 = load i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i64 0, i64 0)
-; TENTRY: %pgocount1 = load i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i64 0, i64 1)
+; NOTENTRY: %pgocount1 = load i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i32 0, i32 0)
+; TENTRY: %pgocount1 = load i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i32 0, i32 1)
 ; CHECK: %1 = add i64 %pgocount1, 1
-; NOTENTRY: store i64 %1, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i64 0, i64 0)
-; ENTRY: store i64 %1, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i64 0, i64 1)
+; NOTENTRY: store i64 %1, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i32 0, i32 0)
+; ENTRY: store i64 %1, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i32 0, i32 1)
   %idxprom = zext i32 %i.0 to i64
   %arrayidx = getelementptr inbounds [200 x i8], [200 x i8]* @"?buffer@@3PADA", i64 0, i64 %idxprom
   %0 = load i8, i8* %arrayidx, align 1
@@ -55,11 +55,11 @@
 
 for.inc:  ; preds = %if.end
 ; CHECK: for.inc:
-; NOTENTRY: %pgocount2 = load i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i64 0, i64 1)
-; ENTRY: %pgocount2 = load i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i64 0, i64 2)
+; NOTENTRY: %pgocount2 = load i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i32 0, i32 1)
+; ENTRY: %pgocount2 = load i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i32 0, i32 2)
 ; CHECK: %3 = add i64 %pgocount2, 1
-; NOTENTRY: store i64 %3, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i64 0, i64 1

[PATCH] D114565: [InstrProf] Attach debug info to counters

2021-11-29 Thread Ellis Hoag via Phabricator via cfe-commits
ellis created this revision.
Herald added subscribers: ormris, wenlei, hiraditya.
ellis edited the summary of this revision.
ellis added reviewers: MaskRay, alanphipps, wenlei, kyulee, davidxl.
ellis edited the summary of this revision.
ellis published this revision for review.
Herald added projects: clang, Sanitizers, LLVM.
Herald added subscribers: llvm-commits, Sanitizers, cfe-commits.

Add the llvm flag `-debug-info-correlate` to attach debug info to 
instrumentation counters so we can correlate raw profile data to their 
functions. Raw profiles are dumped as `.proflite` files. The next diff enables 
`llvm-profdata` to consume `.proflite` and debug info files to produce a normal 
`.profdata` profile.

Part of the "lightweight instrumentation" work: 
https://groups.google.com/g/llvm-dev/c/r03Z6JoN7d4


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114565

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  compiler-rt/include/profile/InstrProfData.inc
  compiler-rt/lib/profile/InstrProfiling.c
  compiler-rt/lib/profile/InstrProfilingMerge.c
  compiler-rt/lib/profile/InstrProfilingWriter.c
  llvm/include/llvm/ProfileData/InstrProf.h
  llvm/include/llvm/ProfileData/InstrProfData.inc
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/lib/ProfileData/InstrProf.cpp
  llvm/lib/ProfileData/InstrProfWriter.cpp
  llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
  llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
  llvm/test/Instrumentation/InstrProfiling/debug-info-correlate.ll

Index: llvm/test/Instrumentation/InstrProfiling/debug-info-correlate.ll
===
--- /dev/null
+++ llvm/test/Instrumentation/InstrProfiling/debug-info-correlate.ll
@@ -0,0 +1,51 @@
+; RUN: opt < %s -instrprof -debug-info-correlate -S > %t.ll
+; RUN: FileCheck < %t.ll %s
+; RUN: llc < %t.ll -mtriple=arm64-unknown-linux-gnu | FileCheck %s --check-prefix CHECK-ASM
+
+target triple = "aarch64-unknown-linux-gnu"
+
+@__profn_foo = private constant [3 x i8] c"foo"
+; CHECK:  @__profc_foo =
+; CHECK-SAME: !dbg ![[EXPR:[0-9]+]]
+
+; CHECK:  ![[EXPR]] = !DIGlobalVariableExpression(var: ![[GLOBAL:[0-9]+]]
+; CHECK:  ![[GLOBAL]] = {{.*}} !DIGlobalVariable(name: "__profc_foo"
+; CHECK-SAME: scope: ![[SCOPE:[0-9]+]]
+; CHECK-SAME: annotations: ![[ANNOTATIONS:[0-9]+]]
+; CHECK:  ![[SCOPE]] = {{.*}} !DISubprogram(name: "foo"
+; CHECK:  ![[ANNOTATIONS]] = !{![[NAME:[0-9]+]], ![[HASH:[0-9]+]], ![[COUNTERS:[0-9]+]]}
+; CHECK:  ![[NAME]] = !{!"Function Name", !"foo"}
+; CHECK:  ![[HASH]] = !{!"CFG Hash", !DIExpression(DW_OP_constu, 12345678,
+; CHECK:  ![[COUNTERS]] = !{!"Num Counters", !DIExpression(DW_OP_constu, 2,
+
+; CHECK-ASM-NOT: .section   __llvm_prf_data
+; CHECK-ASM-NOT: .section   __llvm_prf_names
+
+define void @_Z3foov() !dbg !12 {
+  call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__profn_foo, i32 0, i32 0), i64 12345678, i32 2, i32 0)
+  ret void
+}
+
+declare void @llvm.instrprof.increment(i8*, i64, i32, i32)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !8, !9, !10}
+!llvm.ident = !{!11}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 14.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "debug-info-correlate.cpp", directory: "")
+!2 = !{i32 7, !"Dwarf Version", i32 4}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = !{i32 1, !"wchar_size", i32 4}
+!5 = !{i32 1, !"branch-target-enforcement", i32 0}
+!6 = !{i32 1, !"sign-return-address", i32 0}
+!7 = !{i32 1, !"sign-return-address-all", i32 0}
+!8 = !{i32 1, !"sign-return-address-with-bkey", i32 0}
+!9 = !{i32 7, !"uwtable", i32 1}
+!10 = !{i32 7, !"frame-pointer", i32 1}
+!11 = !{!"clang version 14.0.0"}
+!12 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !13, file: !13, line: 1, type: !14, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !16)
+!13 = !DIFile(filename: "debug-info-correlate.cpp", directory: "")
+!14 = !DISubroutineType(types: !15)
+!15 = !{null}
+!16 = !{}
Index: llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
===
--- llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -291,6 +291,8 @@
 // Command line option to specify the name of the function for CFG dump
 // Defined in Analysis/BlockFrequencyInfo.cpp:  -view-bfi-func-name=
 extern cl::opt ViewBlockFreqFuncName;
+
+extern cl::opt DebugInfoCorrelate;
 } // namespace llvm
 
 static cl::opt
@@ -467,8 +469,9 @@
 createProfileFileNameVar(M, InstrProfileOutput);
 // The variable in a comdat may be discarded by LTO. Ensure the
 // declaration will be retained.
-appendToCompilerUsed(

[PATCH] D114565: [InstrProf] Attach debug info to counters

2021-11-30 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added inline comments.



Comment at: compiler-rt/lib/profile/InstrProfilingWriter.c:273
 
-  if (!DataSize)
+  if (!CountersSize)
 return 0;

kyulee wrote:
> Is it no diff change? I wonder if there is a case where `CountersSize` is 0 
> but not `DataSize`  from a value probe.
> If not, should we make a separate change?
> I wonder if there is a case where CountersSize is 0 but not DataSize from a 
> value probe.
Ah, yes I believe this is possible. I'll fix this here.



Comment at: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp:851
+  addString(AnnotationDie, dwarf::DW_AT_const_value, Value->getString());
+else if (const auto *Expr = dyn_cast(ValueOp))
+  addConstantValue(

kyulee wrote:
> It checks an expression but appears to apply the constant case below. Should 
> it check a constant expression, instead?
Oh we actually don't need to use `DIExpression` at all. Instead we can emit 
`ConstantAsMetadata` to simplify it quite a bit.



Comment at: llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp:647
+  PD.NumValueSites[ValueKind] =
+  std::max(PD.NumValueSites[ValueKind], (uint32_t)(Index + 1));
 }

kyulee wrote:
> It appears this is a NFC. Should we make a separate change?
Yeah I can move this out of this patch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114565/new/

https://reviews.llvm.org/D114565

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


[PATCH] D114565: [InstrProf] Attach debug info to counters

2021-11-30 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 390855.
ellis added a comment.

Emit metadata as `ConstantAsMetadata` instead of the more complicated 
`DIExpression`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114565/new/

https://reviews.llvm.org/D114565

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  compiler-rt/include/profile/InstrProfData.inc
  compiler-rt/lib/profile/InstrProfiling.c
  compiler-rt/lib/profile/InstrProfilingMerge.c
  compiler-rt/lib/profile/InstrProfilingWriter.c
  llvm/include/llvm/ProfileData/InstrProf.h
  llvm/include/llvm/ProfileData/InstrProfData.inc
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/lib/ProfileData/InstrProf.cpp
  llvm/lib/ProfileData/InstrProfWriter.cpp
  llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
  llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
  llvm/test/Instrumentation/InstrProfiling/debug-info-correlate.ll

Index: llvm/test/Instrumentation/InstrProfiling/debug-info-correlate.ll
===
--- /dev/null
+++ llvm/test/Instrumentation/InstrProfiling/debug-info-correlate.ll
@@ -0,0 +1,74 @@
+; RUN: opt < %s -instrprof -debug-info-correlate -S > %t.ll
+; RUN: llc < %t.ll --filetype=asm > %t.s
+; RUN: llc < %t.ll --filetype=obj > %t.o
+; RUN: FileCheck < %t.ll %s
+; RUN: llvm-dwarfdump %t.o | FileCheck %s --implicit-check-not "{{DW_TAG|NULL}}" --check-prefix CHECK-DWARF
+; RUN: FileCheck < %t.s %s --check-prefix CHECK-ASM
+
+target triple = "aarch64-unknown-linux-gnu"
+
+@__profn_foo = private constant [3 x i8] c"foo"
+; CHECK:  @__profc_foo =
+; CHECK-SAME: !dbg ![[EXPR:[0-9]+]]
+
+; CHECK:  ![[EXPR]] = !DIGlobalVariableExpression(var: ![[GLOBAL:[0-9]+]]
+; CHECK:  ![[GLOBAL]] = {{.*}} !DIGlobalVariable(name: "__profc_foo"
+; CHECK-SAME: scope: ![[SCOPE:[0-9]+]]
+; CHECK-SAME: annotations: ![[ANNOTATIONS:[0-9]+]]
+; CHECK:  ![[SCOPE]] = {{.*}} !DISubprogram(name: "foo"
+; CHECK:  ![[ANNOTATIONS]] = !{![[NAME:[0-9]+]], ![[HASH:[0-9]+]], ![[COUNTERS:[0-9]+]]}
+; CHECK:  ![[NAME]] = !{!"Function Name", !"foo"}
+; CHECK:  ![[HASH]] = !{!"CFG Hash", i64 12345678}
+; CHECK:  ![[COUNTERS]] = !{!"Num Counters", i32 2}
+
+define void @_Z3foov() !dbg !12 {
+  call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__profn_foo, i32 0, i32 0), i64 12345678, i32 2, i32 0)
+  ret void
+}
+
+declare void @llvm.instrprof.increment(i8*, i64, i32, i32)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !8, !9, !10}
+!llvm.ident = !{!11}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 14.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "debug-info-correlate.cpp", directory: "")
+!2 = !{i32 7, !"Dwarf Version", i32 4}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = !{i32 1, !"wchar_size", i32 4}
+!5 = !{i32 1, !"branch-target-enforcement", i32 0}
+!6 = !{i32 1, !"sign-return-address", i32 0}
+!7 = !{i32 1, !"sign-return-address-all", i32 0}
+!8 = !{i32 1, !"sign-return-address-with-bkey", i32 0}
+!9 = !{i32 7, !"uwtable", i32 1}
+!10 = !{i32 7, !"frame-pointer", i32 1}
+!11 = !{!"clang version 14.0.0"}
+!12 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !13, file: !13, line: 1, type: !14, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !16)
+!13 = !DIFile(filename: "debug-info-correlate.cpp", directory: "")
+!14 = !DISubroutineType(types: !15)
+!15 = !{null}
+!16 = !{}
+
+; CHECK-DWARF: DW_TAG_compile_unit
+; CHECK-DWARF:   DW_TAG_subprogram
+; CHECK-DWARF: DW_AT_name	("foo")
+; CHECK-DWARF: DW_TAG_variable
+; CHECK-DWARF:   DW_AT_name	("__profc_foo")
+; CHECK-DWARF:   DW_AT_type	({{.*}} "Profile Data Type")
+; CHECK-DWARF:   DW_TAG_LLVM_annotation
+; CHECK-DWARF: DW_AT_name	("Function Name")
+; CHECK-DWARF: DW_AT_const_value	("foo")
+; CHECK-DWARF:   DW_TAG_LLVM_annotation
+; CHECK-DWARF: DW_AT_name	("CFG Hash")
+; CHECK-DWARF: DW_AT_const_value	(12345678)
+; CHECK-DWARF:   DW_TAG_LLVM_annotation
+; CHECK-DWARF: DW_AT_name	("Num Counters")
+; CHECK-DWARF: DW_AT_const_value	(2)
+; CHECK-DWARF:   NULL
+; CHECK-DWARF: NULL
+; CHECK-DWARF:   DW_TAG_unspecified_type
+; CHECK-DWARF:   NULL
+
+; CHECK-ASM-NOT: .section   __llvm_prf_data
+; CHECK-ASM-NOT: .section   __llvm_prf_names
Index: llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
===
--- llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -291,6 +291,8 @@
 // Command line option to specify the name of the function for CFG dump
 // Defined in Analysis/BlockFrequencyInfo.cpp:  -view-bfi-func-name

[PATCH] D114565: [InstrProf] Attach debug info to counters

2021-12-03 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added inline comments.



Comment at: llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp:961
+  DB.finalize();
+}
+  }

kyulee wrote:
> I think when `-debug-info-correlate` is used without debug info, we should 
> fail or emit a warning here instead of silently proceeding it because we 
> cannot correlate it anyhow down the road.
I'll emit a warning. I don't want to fail in this case when a single function 
doesn't have debug info. Instead, I'm planning on adding a check in the 
frontend when parsing the `-fprofile-generate-correlate=debug-info` flag (which 
I will add later).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114565/new/

https://reviews.llvm.org/D114565

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


[PATCH] D114565: [InstrProf] Attach debug info to counters

2021-12-03 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 391780.
ellis added a comment.

Add warning when debug info is missing.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114565/new/

https://reviews.llvm.org/D114565

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  compiler-rt/include/profile/InstrProfData.inc
  compiler-rt/lib/profile/InstrProfiling.c
  compiler-rt/lib/profile/InstrProfilingMerge.c
  compiler-rt/lib/profile/InstrProfilingWriter.c
  llvm/include/llvm/ProfileData/InstrProf.h
  llvm/include/llvm/ProfileData/InstrProfData.inc
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/lib/ProfileData/InstrProf.cpp
  llvm/lib/ProfileData/InstrProfWriter.cpp
  llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
  llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
  llvm/test/Instrumentation/InstrProfiling/debug-info-correlate.ll

Index: llvm/test/Instrumentation/InstrProfiling/debug-info-correlate.ll
===
--- /dev/null
+++ llvm/test/Instrumentation/InstrProfiling/debug-info-correlate.ll
@@ -0,0 +1,74 @@
+; RUN: opt < %s -instrprof -debug-info-correlate -S > %t.ll
+; RUN: llc < %t.ll --filetype=asm > %t.s
+; RUN: llc < %t.ll --filetype=obj > %t.o
+; RUN: FileCheck < %t.ll %s
+; RUN: llvm-dwarfdump %t.o | FileCheck %s --implicit-check-not "{{DW_TAG|NULL}}" --check-prefix CHECK-DWARF
+; RUN: FileCheck < %t.s %s --check-prefix CHECK-ASM
+
+target triple = "aarch64-unknown-linux-gnu"
+
+@__profn_foo = private constant [3 x i8] c"foo"
+; CHECK:  @__profc_foo =
+; CHECK-SAME: !dbg ![[EXPR:[0-9]+]]
+
+; CHECK:  ![[EXPR]] = !DIGlobalVariableExpression(var: ![[GLOBAL:[0-9]+]]
+; CHECK:  ![[GLOBAL]] = {{.*}} !DIGlobalVariable(name: "__profc_foo"
+; CHECK-SAME: scope: ![[SCOPE:[0-9]+]]
+; CHECK-SAME: annotations: ![[ANNOTATIONS:[0-9]+]]
+; CHECK:  ![[SCOPE]] = {{.*}} !DISubprogram(name: "foo"
+; CHECK:  ![[ANNOTATIONS]] = !{![[NAME:[0-9]+]], ![[HASH:[0-9]+]], ![[COUNTERS:[0-9]+]]}
+; CHECK:  ![[NAME]] = !{!"Function Name", !"foo"}
+; CHECK:  ![[HASH]] = !{!"CFG Hash", i64 12345678}
+; CHECK:  ![[COUNTERS]] = !{!"Num Counters", i32 2}
+
+define void @_Z3foov() !dbg !12 {
+  call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__profn_foo, i32 0, i32 0), i64 12345678, i32 2, i32 0)
+  ret void
+}
+
+declare void @llvm.instrprof.increment(i8*, i64, i32, i32)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !8, !9, !10}
+!llvm.ident = !{!11}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 14.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "debug-info-correlate.cpp", directory: "")
+!2 = !{i32 7, !"Dwarf Version", i32 4}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = !{i32 1, !"wchar_size", i32 4}
+!5 = !{i32 1, !"branch-target-enforcement", i32 0}
+!6 = !{i32 1, !"sign-return-address", i32 0}
+!7 = !{i32 1, !"sign-return-address-all", i32 0}
+!8 = !{i32 1, !"sign-return-address-with-bkey", i32 0}
+!9 = !{i32 7, !"uwtable", i32 1}
+!10 = !{i32 7, !"frame-pointer", i32 1}
+!11 = !{!"clang version 14.0.0"}
+!12 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !13, file: !13, line: 1, type: !14, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !16)
+!13 = !DIFile(filename: "debug-info-correlate.cpp", directory: "")
+!14 = !DISubroutineType(types: !15)
+!15 = !{null}
+!16 = !{}
+
+; CHECK-DWARF: DW_TAG_compile_unit
+; CHECK-DWARF:   DW_TAG_subprogram
+; CHECK-DWARF: DW_AT_name	("foo")
+; CHECK-DWARF: DW_TAG_variable
+; CHECK-DWARF:   DW_AT_name	("__profc_foo")
+; CHECK-DWARF:   DW_AT_type	({{.*}} "Profile Data Type")
+; CHECK-DWARF:   DW_TAG_LLVM_annotation
+; CHECK-DWARF: DW_AT_name	("Function Name")
+; CHECK-DWARF: DW_AT_const_value	("foo")
+; CHECK-DWARF:   DW_TAG_LLVM_annotation
+; CHECK-DWARF: DW_AT_name	("CFG Hash")
+; CHECK-DWARF: DW_AT_const_value	(12345678)
+; CHECK-DWARF:   DW_TAG_LLVM_annotation
+; CHECK-DWARF: DW_AT_name	("Num Counters")
+; CHECK-DWARF: DW_AT_const_value	(2)
+; CHECK-DWARF:   NULL
+; CHECK-DWARF: NULL
+; CHECK-DWARF:   DW_TAG_unspecified_type
+; CHECK-DWARF:   NULL
+
+; CHECK-ASM-NOT: .section   __llvm_prf_data
+; CHECK-ASM-NOT: .section   __llvm_prf_names
Index: llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
===
--- llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -291,6 +291,8 @@
 // Command line option to specify the name of the function for CFG dump
 // Defined in Analysis/BlockFrequencyInfo.cpp:  -view-bfi-func-name=
 extern cl::opt ViewBlockFreqFuncName;
+
+ext

[PATCH] D136385: Add support for MC/DC in LLVM Source-Based Code Coverage

2022-10-24 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added inline comments.



Comment at: llvm/lib/ProfileData/InstrProfCorrelator.cpp:208
   maybeSwap(CounterOffset),
+  maybeSwap(BitmaskOffset),
   maybeSwap(FunctionPtr),

Since `BitmaskOffset` and `NumBitmaskBytes` are always zero, I would rather set 
them as zero here rather than passing in more parameters. See `ValuesPtr`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136385/new/

https://reviews.llvm.org/D136385

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


[PATCH] D135926: [clang] Fix crash with -funique-internal-linkage-names

2022-10-13 Thread Ellis Hoag via Phabricator via cfe-commits
ellis created this revision.
Herald added a project: All.
ellis added reviewers: tmsriram, hoy, dblaikie.
ellis published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Calling `getFunctionLinkage(CalleeInfo.getCalleeDecl())` will crash when the 
declaration does not have a body, e.g., `extern void foo();`. Instead, we can 
use `isExternallyVisible()` to see if the delcaration has internal linkage.

I believe using `!isExternallyVisible()` is correct because the clang linkage 
must be `InternalLinkage` or `UniqueExternalLinkage`, both of which are 
"internal linkage" in llvm.
https://github.com/llvm/llvm-project/blob/9c26f51f5e178ac0fda98419e3a61d205d3b58b1/clang/include/clang/Basic/Linkage.h#L28-L40

Fixes https://github.com/llvm/llvm-project/issues/54139


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135926

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGen/unique-internal-linkage-names.c


Index: clang/test/CodeGen/unique-internal-linkage-names.c
===
--- /dev/null
+++ clang/test/CodeGen/unique-internal-linkage-names.c
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 %s -S -emit-llvm -funique-internal-linkage-names -o - | 
FileCheck %s
+
+// Check that we do not crash when overloading extern functions.
+
+inline void overloaded_external() {}
+extern void overloaded_external();
+
+// CHECK: define internal void @overloaded_internal() [[ATTR:#[0-9]+]] {
+static void overloaded_internal() {}
+extern void overloaded_internal();
+
+void markUsed() {
+  overloaded_external();
+  overloaded_internal();
+}
+
+// CHECK: attributes [[ATTR]] =
+// CHECK-SAME: "sample-profile-suffix-elision-policy"="selected"
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -2260,9 +2260,8 @@
   // Add "sample-profile-suffix-elision-policy" attribute for internal linkage
   // functions with -funique-internal-linkage-names.
   if (TargetDecl && CodeGenOpts.UniqueInternalLinkageNames) {
-if (isa(TargetDecl)) {
-  if (this->getFunctionLinkage(CalleeInfo.getCalleeDecl()) ==
-  llvm::GlobalValue::InternalLinkage)
+if (const auto *FD = dyn_cast_or_null(TargetDecl)) {
+  if (!FD->isExternallyVisible())
 FuncAttrs.addAttribute("sample-profile-suffix-elision-policy",
"selected");
 }


Index: clang/test/CodeGen/unique-internal-linkage-names.c
===
--- /dev/null
+++ clang/test/CodeGen/unique-internal-linkage-names.c
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 %s -S -emit-llvm -funique-internal-linkage-names -o - | FileCheck %s
+
+// Check that we do not crash when overloading extern functions.
+
+inline void overloaded_external() {}
+extern void overloaded_external();
+
+// CHECK: define internal void @overloaded_internal() [[ATTR:#[0-9]+]] {
+static void overloaded_internal() {}
+extern void overloaded_internal();
+
+void markUsed() {
+  overloaded_external();
+  overloaded_internal();
+}
+
+// CHECK: attributes [[ATTR]] =
+// CHECK-SAME: "sample-profile-suffix-elision-policy"="selected"
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -2260,9 +2260,8 @@
   // Add "sample-profile-suffix-elision-policy" attribute for internal linkage
   // functions with -funique-internal-linkage-names.
   if (TargetDecl && CodeGenOpts.UniqueInternalLinkageNames) {
-if (isa(TargetDecl)) {
-  if (this->getFunctionLinkage(CalleeInfo.getCalleeDecl()) ==
-  llvm::GlobalValue::InternalLinkage)
+if (const auto *FD = dyn_cast_or_null(TargetDecl)) {
+  if (!FD->isExternallyVisible())
 FuncAttrs.addAttribute("sample-profile-suffix-elision-policy",
"selected");
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D135926: [clang] Fix crash with -funique-internal-linkage-names

2022-10-17 Thread Ellis Hoag via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG970e1ea01aa0: [clang] Fix crash with 
-funique-internal-linkage-names (authored by ellis).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135926/new/

https://reviews.llvm.org/D135926

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGen/unique-internal-linkage-names.c


Index: clang/test/CodeGen/unique-internal-linkage-names.c
===
--- /dev/null
+++ clang/test/CodeGen/unique-internal-linkage-names.c
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 %s -S -emit-llvm -funique-internal-linkage-names -o - | 
FileCheck %s
+
+// Check that we do not crash when overloading extern functions.
+
+inline void overloaded_external() {}
+extern void overloaded_external();
+
+// CHECK: define internal void @overloaded_internal() [[ATTR:#[0-9]+]] {
+static void overloaded_internal() {}
+extern void overloaded_internal();
+
+void markUsed() {
+  overloaded_external();
+  overloaded_internal();
+}
+
+// CHECK: attributes [[ATTR]] =
+// CHECK-SAME: "sample-profile-suffix-elision-policy"="selected"
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -2264,9 +2264,8 @@
   // Add "sample-profile-suffix-elision-policy" attribute for internal linkage
   // functions with -funique-internal-linkage-names.
   if (TargetDecl && CodeGenOpts.UniqueInternalLinkageNames) {
-if (isa(TargetDecl)) {
-  if (this->getFunctionLinkage(CalleeInfo.getCalleeDecl()) ==
-  llvm::GlobalValue::InternalLinkage)
+if (const auto *FD = dyn_cast_or_null(TargetDecl)) {
+  if (!FD->isExternallyVisible())
 FuncAttrs.addAttribute("sample-profile-suffix-elision-policy",
"selected");
 }


Index: clang/test/CodeGen/unique-internal-linkage-names.c
===
--- /dev/null
+++ clang/test/CodeGen/unique-internal-linkage-names.c
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 %s -S -emit-llvm -funique-internal-linkage-names -o - | FileCheck %s
+
+// Check that we do not crash when overloading extern functions.
+
+inline void overloaded_external() {}
+extern void overloaded_external();
+
+// CHECK: define internal void @overloaded_internal() [[ATTR:#[0-9]+]] {
+static void overloaded_internal() {}
+extern void overloaded_internal();
+
+void markUsed() {
+  overloaded_external();
+  overloaded_internal();
+}
+
+// CHECK: attributes [[ATTR]] =
+// CHECK-SAME: "sample-profile-suffix-elision-policy"="selected"
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -2264,9 +2264,8 @@
   // Add "sample-profile-suffix-elision-policy" attribute for internal linkage
   // functions with -funique-internal-linkage-names.
   if (TargetDecl && CodeGenOpts.UniqueInternalLinkageNames) {
-if (isa(TargetDecl)) {
-  if (this->getFunctionLinkage(CalleeInfo.getCalleeDecl()) ==
-  llvm::GlobalValue::InternalLinkage)
+if (const auto *FD = dyn_cast_or_null(TargetDecl)) {
+  if (!FD->isExternallyVisible())
 FuncAttrs.addAttribute("sample-profile-suffix-elision-policy",
"selected");
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157913: [Coverage] Allow Clang coverage to be used with debug info correlation.

2023-09-19 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added a comment.

In D157913#4648296 , @zequanwu wrote:

> For some unknown reasons, linker still generates __llvm_prf_names section in 
> the final binary on mac even if the object file doesn't have this section. 
> And I cannot use llvm-objdump to get anything from that section.
>
>   $ llvm-readelf -S ../tmp/a.out
>   ...
> Section {
>   Index: 15
>   Name: __llvm_prf_names (5F 5F 6C 6C 76 6D 5F 70 72 66 5F 6E 61 6D 65 73)
>   Segment: __DATA (5F 5F 44 41 54 41 00 00 00 00 00 00 00 00 00 00)
>   Address: 0x100018000
>   Size: 0x0
>   Offset: 98304
>   Alignment: 0
>   RelocationOffset: 0x0
>   RelocationCount: 0
>   Type: Regular (0x0)
>   Attributes [ (0x0)
>   ]
>   Reserved1: 0x0
>   Reserved2: 0x0
>   Reserved3: 0x0
> }
>   ...
>   $ llvm-objdump --section=__llvm_prf_names --full-contents ../tmp/a.out
>   ../tmp/a.out:   file format mach-o arm64
>
> I will delete the test for now as it's not working on mac: 
> `compiler-rt/test/profile/Darwin/coverage-debug-info-correlate.cpp`

I have seen that MachO sections remain in the header even if the size is zero 
which seems to be the case here. You could use `llvm-objdump` to verify that 
the section exists but the size is zero.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157913/new/

https://reviews.llvm.org/D157913

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


[PATCH] D154014: [SpecialCaseList] Use Globs instead of Regex

2023-07-20 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 542732.
ellis added a comment.

If `#!special-case-list-v2` is the first line in the special case list, then we 
will use globs to match patterns. Otherwise, we fall back to the original 
behavior of using regexes to match patterns. Once this feature is stable, and 
after a version cut, we can remove the regex case.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154014/new/

https://reviews.llvm.org/D154014

Files:
  clang/docs/SanitizerSpecialCaseList.rst
  clang/lib/Basic/ProfileList.cpp
  clang/lib/Basic/SanitizerSpecialCaseList.cpp
  llvm/include/llvm/Support/SpecialCaseList.h
  llvm/lib/Support/SpecialCaseList.cpp
  llvm/unittests/Support/SpecialCaseListTest.cpp

Index: llvm/unittests/Support/SpecialCaseListTest.cpp
===
--- llvm/unittests/Support/SpecialCaseListTest.cpp
+++ llvm/unittests/Support/SpecialCaseListTest.cpp
@@ -10,8 +10,11 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/VirtualFileSystem.h"
+#include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
+using testing::HasSubstr;
+using testing::StartsWith;
 using namespace llvm;
 
 namespace {
@@ -19,24 +22,32 @@
 class SpecialCaseListTest : public ::testing::Test {
 protected:
   std::unique_ptr makeSpecialCaseList(StringRef List,
-   std::string &Error) {
-std::unique_ptr MB = MemoryBuffer::getMemBuffer(List);
+   std::string &Error,
+   bool UseGlobs = true) {
+auto S = List.str();
+if (UseGlobs)
+  S = (Twine("#!special-case-list-v2\n") + S).str();
+std::unique_ptr MB = MemoryBuffer::getMemBuffer(S);
 return SpecialCaseList::create(MB.get(), Error);
   }
 
-  std::unique_ptr makeSpecialCaseList(StringRef List) {
+  std::unique_ptr makeSpecialCaseList(StringRef List,
+   bool UseGlobs = true) {
 std::string Error;
-auto SCL = makeSpecialCaseList(List, Error);
+auto SCL = makeSpecialCaseList(List, Error, UseGlobs);
 assert(SCL);
 assert(Error == "");
 return SCL;
   }
 
-  std::string makeSpecialCaseListFile(StringRef Contents) {
+  std::string makeSpecialCaseListFile(StringRef Contents,
+  bool UseGlobs = true) {
 int FD;
 SmallString<64> Path;
 sys::fs::createTemporaryFile("SpecialCaseListTest", "temp", FD, Path);
 raw_fd_ostream OF(FD, true, true);
+if (UseGlobs)
+  OF << "#!special-case-list-v2\n";
 OF << Contents;
 OF.close();
 return std::string(Path.str());
@@ -59,10 +70,10 @@
   EXPECT_FALSE(SCL->inSection("", "fun", "hello"));
   EXPECT_FALSE(SCL->inSection("", "src", "hello", "category"));
 
-  EXPECT_EQ(3u, SCL->inSectionBlame("", "src", "hello"));
-  EXPECT_EQ(4u, SCL->inSectionBlame("", "src", "bye"));
-  EXPECT_EQ(5u, SCL->inSectionBlame("", "src", "hi", "category"));
-  EXPECT_EQ(6u, SCL->inSectionBlame("", "src", "", "category"));
+  EXPECT_EQ(4u, SCL->inSectionBlame("", "src", "hello"));
+  EXPECT_EQ(5u, SCL->inSectionBlame("", "src", "bye"));
+  EXPECT_EQ(6u, SCL->inSectionBlame("", "src", "hi", "category"));
+  EXPECT_EQ(7u, SCL->inSectionBlame("", "src", "", "category"));
   EXPECT_EQ(0u, SCL->inSectionBlame("", "src", "hi"));
   EXPECT_EQ(0u, SCL->inSectionBlame("", "fun", "hello"));
   EXPECT_EQ(0u, SCL->inSectionBlame("", "src", "hello", "category"));
@@ -74,31 +85,29 @@
  "\n"
  "[not valid\n",
  Error));
-  EXPECT_TRUE(
-  ((StringRef)Error).startswith("malformed section header on line 3:"));
+  EXPECT_THAT(Error, StartsWith("malformed section header on line 4:"));
 
   EXPECT_EQ(nullptr, makeSpecialCaseList("\n\n\n"
  "[not valid\n",
  Error));
-  EXPECT_TRUE(
-  ((StringRef)Error).startswith("malformed section header on line 4:"));
+  EXPECT_THAT(Error, StartsWith("malformed section header on line 5:"));
 }
 
-TEST_F(SpecialCaseListTest, SectionRegexErrorHandling) {
+TEST_F(SpecialCaseListTest, SectionGlobErrorHandling) {
   std::string Error;
   EXPECT_EQ(makeSpecialCaseList("[address", Error), nullptr);
-  EXPECT_TRUE(((StringRef)Error).startswith("malformed section header "));
+  EXPECT_THAT(Error, StartsWith("malformed section header "));
 
   EXPECT_EQ(makeSpecialCaseList("[[]", Error), nullptr);
-  EXPECT_TRUE(((StringRef)Error).startswith("malformed regex for section [: "));
+  EXPECT_EQ(Error, "malformed section at line 2: '[': invalid glob pattern: [");
 
   EXPECT_EQ(makeSpecialCaseList("src:=", Error), nullptr);
-  EXPECT_TRUE(((StringRef)Error).endswith("Supplied regexp wa

[PATCH] D157632: [Profile] Allow online merging with debug info correlation.

2023-08-10 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added a comment.

Thanks for working on this!




Comment at: compiler-rt/lib/profile/InstrProfilingMerge.c:103-104
 COMPILER_RT_VISIBILITY
 int __llvm_profile_merge_from_buffer(const char *ProfileData,
  uint64_t ProfileSize) {
   __llvm_profile_data *SrcDataStart, *SrcDataEnd, *SrcData, *DstData;

I just realized that I need to throw an error here for temporal profiles since 
online merging won't work for that case.



Comment at: compiler-rt/lib/profile/InstrProfilingMerge.c:129
+  // enabled.
+  if (Header->DataSize == 0) {
+if (!(__llvm_profile_get_version() & VARIANT_MASK_DBG_CORRELATE)) {

Since we don't have the data section, we need to be confident that existing 
profile comes from the same binary (so that the counter section is identical). 
Can we add some extra checks here? I'm thinking we can verify that some fields 
in the headers match and that the variant flags are identical.



Comment at: compiler-rt/lib/profile/InstrProfilingMerge.c:134-136
+for (SrcCounter = SrcCountersStart,
+DstCounter = __llvm_profile_begin_counters();
+ SrcCounter < SrcCountersEnd;) {

Can you add a check to make sure src and dst have the same number of counters 
(`SrcCountersEnd - SrcCountersStart`)?



Comment at: compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c:26
+// RUN: %clang_pgogen -o %t -g -mllvm --debug-info-correlate -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.profdir/%m.proflite %run %t
+// RUN: llvm-profdata merge -o %t.profdata --debug-info=%t.dSYM %t.profdir/

We need to run this line twice to correctly test 
`__llvm_profile_merge_from_buffer()`



Comment at: compiler-rt/test/profile/Linux/instrprof-debug-info-correlate.c:35
+
+// RUN: diff <(llvm-profdata show %t.normal.profdata) <(llvm-profdata show 
%t.profdata)
+

I know this is outside the scope of this patch, but I don't think simply 
`llvm-profdata show` is sufficient to compare profiles. I'll try to fix this.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157632/new/

https://reviews.llvm.org/D157632

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


[PATCH] D157632: [Profile] Allow online merging with debug info correlation.

2023-08-10 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added a comment.

I've just published https://reviews.llvm.org/D157664, so you'll want to rebase 
ontop of it if it lands soon. I would also like to see some more tests added to 
`instrprof-merge-error.c` to make sure two different binaries can't merge 
profiles together with `--debug-info-correlate`. I was thinking the test would 
be something like this.

  // RUN: %clang_pgogen -o %t/a -g -mllvm --debug-info-correlate -mllvm 
--disable-vp=true %t/main.c
  // RUN: %clang_pgogen -o %t/b -g -mllvm --debug-info-correlate -mllvm 
--disable-vp=true %t/main.c %t/foo.c
  // RUN: env LLVM_PROFILE_FILE=%t/default_%m.profdata %run %t/a
  // This next line should fail to merge because the counter sections have 
different sizes
  // RUN: env LLVM_PROFILE_FILE=%t/default_%m.profdata %run %t/b
  
  //--- main.c
  int main() { return 0; }
  //--- foo.c
  int foo() { return 4; }


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157632/new/

https://reviews.llvm.org/D157632

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


[PATCH] D157632: [Profile] Allow online merging with debug info correlation.

2023-08-11 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added a comment.

In D157632#4580576 , @zequanwu wrote:

> BTW, I noticed something strange with `-pgo-function-entry-coverage` when 
> merging via llvm-profdata.

This is intentional. The two raw profiles individually store blocks as either 
covered or not, but when we merge them they get converted to counters and 
accumulated.
https://github.com/llvm/llvm-project/blob/6a0feb1503e21432e63d93b44357bad43f8026d1/llvm/lib/ProfileData/InstrProf.cpp#L726
Then in `PGOUseFunc::populateCoverage()` we annotate blocks as alive if their 
counter value is non-zero.
https://github.com/llvm/llvm-project/blob/1aee2434ce4c9b5785cbc8f72cbbbd64f9e85297/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp#L1399
My logic was that the indexed profile represents these counters as ints, so we 
might as well accumulate them. Also, this makes the implementation simpler.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157632/new/

https://reviews.llvm.org/D157632

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


[PATCH] D157904: Improve reliability of CompilationDatabaseTest

2023-08-14 Thread Ellis Hoag via Phabricator via cfe-commits
ellis created this revision.
Herald added a subscriber: ChuanqiXu.
Herald added a project: All.
ellis requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157904

Files:
  clang/unittests/Tooling/CompilationDatabaseTest.cpp


Index: clang/unittests/Tooling/CompilationDatabaseTest.cpp
===
--- clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -6,9 +6,6 @@
 //
 
//===--===//
 
-#include "clang/AST/DeclCXX.h"
-#include "clang/AST/DeclGroup.h"
-#include "clang/Frontend/FrontendAction.h"
 #include "clang/Tooling/CompilationDatabase.h"
 #include "clang/Tooling/FileMatchTrie.h"
 #include "clang/Tooling/JSONCompilationDatabase.h"
@@ -24,6 +21,8 @@
 
 using testing::ElementsAre;
 using testing::EndsWith;
+using testing::IsEmpty;
+using testing::UnorderedElementsAreArray;
 
 static void expectFailure(StringRef JSONDatabase, StringRef Explanation) {
   std::string ErrorMessage;
@@ -83,8 +82,8 @@
 
 TEST(JSONCompilationDatabase, GetAllFiles) {
   std::string ErrorMessage;
-  EXPECT_EQ(std::vector(),
-getAllFiles("[]", ErrorMessage, JSONCommandLineSyntax::Gnu))
+  EXPECT_THAT(getAllFiles("[]", ErrorMessage, JSONCommandLineSyntax::Gnu),
+  IsEmpty())
   << ErrorMessage;
 
   std::vector expected_files;
@@ -97,8 +96,7 @@
   expected_files.push_back(std::string(PathStorage.str()));
   llvm::sys::path::native("//net/file1", PathStorage);
   expected_files.push_back(std::string(PathStorage.str()));
-  EXPECT_EQ(expected_files,
-getAllFiles(R"json(
+  EXPECT_THAT(getAllFiles(R"json(
 [
   {
 "directory": "//net/dir",
@@ -121,7 +119,8 @@
 "file": "//net/dir/foo/../file3"
   }
 ])json",
-ErrorMessage, JSONCommandLineSyntax::Gnu))
+  ErrorMessage, JSONCommandLineSyntax::Gnu),
+  UnorderedElementsAreArray(expected_files))
   << ErrorMessage;
 }
 
@@ -550,7 +549,7 @@
   CommandLine.push_back("two");
   FixedCompilationDatabase Database(".", CommandLine);
 
-  EXPECT_EQ(0ul, Database.getAllFiles().size());
+  EXPECT_THAT(Database.getAllFiles(), IsEmpty());
 }
 
 TEST(FixedCompilationDatabase, GetAllCompileCommands) {


Index: clang/unittests/Tooling/CompilationDatabaseTest.cpp
===
--- clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -6,9 +6,6 @@
 //
 //===--===//
 
-#include "clang/AST/DeclCXX.h"
-#include "clang/AST/DeclGroup.h"
-#include "clang/Frontend/FrontendAction.h"
 #include "clang/Tooling/CompilationDatabase.h"
 #include "clang/Tooling/FileMatchTrie.h"
 #include "clang/Tooling/JSONCompilationDatabase.h"
@@ -24,6 +21,8 @@
 
 using testing::ElementsAre;
 using testing::EndsWith;
+using testing::IsEmpty;
+using testing::UnorderedElementsAreArray;
 
 static void expectFailure(StringRef JSONDatabase, StringRef Explanation) {
   std::string ErrorMessage;
@@ -83,8 +82,8 @@
 
 TEST(JSONCompilationDatabase, GetAllFiles) {
   std::string ErrorMessage;
-  EXPECT_EQ(std::vector(),
-getAllFiles("[]", ErrorMessage, JSONCommandLineSyntax::Gnu))
+  EXPECT_THAT(getAllFiles("[]", ErrorMessage, JSONCommandLineSyntax::Gnu),
+  IsEmpty())
   << ErrorMessage;
 
   std::vector expected_files;
@@ -97,8 +96,7 @@
   expected_files.push_back(std::string(PathStorage.str()));
   llvm::sys::path::native("//net/file1", PathStorage);
   expected_files.push_back(std::string(PathStorage.str()));
-  EXPECT_EQ(expected_files,
-getAllFiles(R"json(
+  EXPECT_THAT(getAllFiles(R"json(
 [
   {
 "directory": "//net/dir",
@@ -121,7 +119,8 @@
 "file": "//net/dir/foo/../file3"
   }
 ])json",
-ErrorMessage, JSONCommandLineSyntax::Gnu))
+  ErrorMessage, JSONCommandLineSyntax::Gnu),
+  UnorderedElementsAreArray(expected_files))
   << ErrorMessage;
 }
 
@@ -550,7 +549,7 @@
   CommandLine.push_back("two");
   FixedCompilationDatabase Database(".", CommandLine);
 
-  EXPECT_EQ(0ul, Database.getAllFiles().size());
+  EXPECT_THAT(Database.getAllFiles(), IsEmpty());
 }
 
 TEST(FixedCompilationDatabase, GetAllCompileCommands) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157632: [Profile] Allow online merging with debug info correlation.

2023-08-14 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added inline comments.



Comment at: compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c:24
+
+// RUN: rm -rf %t.profdir && mkdir %t.profdir
+

Let's move this line down since we don't use it until line 31.



Comment at: compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c:30
+
+// RUN: %clang_pgogen -o %t -g -mllvm --debug-info-correlate -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.profdir/%m.proflite %run %t

This looks to be the same as line 2. Lets just reuse that executable.



Comment at: compiler-rt/test/profile/Darwin/instrprof-debug-info-correlate.c:39
+
+// RUN: %clang_pgogen -o %t.cov -g -mllvm --debug-info-correlate -mllvm 
-pgo-function-entry-coverage -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.profdir/%m.cov.proflite %run %t.cov

Same here. This is the same as line 12. (And I believe these comments also 
apply to the Linux test)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157632/new/

https://reviews.llvm.org/D157632

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


[PATCH] D157904: Improve reliability of CompilationDatabaseTest

2023-08-14 Thread Ellis Hoag via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9e11d6850a5a: Improve reliability of CompilationDatabaseTest 
(authored by ellis).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157904/new/

https://reviews.llvm.org/D157904

Files:
  clang/unittests/Tooling/CompilationDatabaseTest.cpp


Index: clang/unittests/Tooling/CompilationDatabaseTest.cpp
===
--- clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -6,9 +6,6 @@
 //
 
//===--===//
 
-#include "clang/AST/DeclCXX.h"
-#include "clang/AST/DeclGroup.h"
-#include "clang/Frontend/FrontendAction.h"
 #include "clang/Tooling/CompilationDatabase.h"
 #include "clang/Tooling/FileMatchTrie.h"
 #include "clang/Tooling/JSONCompilationDatabase.h"
@@ -24,6 +21,8 @@
 
 using testing::ElementsAre;
 using testing::EndsWith;
+using testing::IsEmpty;
+using testing::UnorderedElementsAreArray;
 
 static void expectFailure(StringRef JSONDatabase, StringRef Explanation) {
   std::string ErrorMessage;
@@ -83,8 +82,8 @@
 
 TEST(JSONCompilationDatabase, GetAllFiles) {
   std::string ErrorMessage;
-  EXPECT_EQ(std::vector(),
-getAllFiles("[]", ErrorMessage, JSONCommandLineSyntax::Gnu))
+  EXPECT_THAT(getAllFiles("[]", ErrorMessage, JSONCommandLineSyntax::Gnu),
+  IsEmpty())
   << ErrorMessage;
 
   std::vector expected_files;
@@ -97,8 +96,7 @@
   expected_files.push_back(std::string(PathStorage.str()));
   llvm::sys::path::native("//net/file1", PathStorage);
   expected_files.push_back(std::string(PathStorage.str()));
-  EXPECT_EQ(expected_files,
-getAllFiles(R"json(
+  EXPECT_THAT(getAllFiles(R"json(
 [
   {
 "directory": "//net/dir",
@@ -121,7 +119,8 @@
 "file": "//net/dir/foo/../file3"
   }
 ])json",
-ErrorMessage, JSONCommandLineSyntax::Gnu))
+  ErrorMessage, JSONCommandLineSyntax::Gnu),
+  UnorderedElementsAreArray(expected_files))
   << ErrorMessage;
 }
 
@@ -550,7 +549,7 @@
   CommandLine.push_back("two");
   FixedCompilationDatabase Database(".", CommandLine);
 
-  EXPECT_EQ(0ul, Database.getAllFiles().size());
+  EXPECT_THAT(Database.getAllFiles(), IsEmpty());
 }
 
 TEST(FixedCompilationDatabase, GetAllCompileCommands) {


Index: clang/unittests/Tooling/CompilationDatabaseTest.cpp
===
--- clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -6,9 +6,6 @@
 //
 //===--===//
 
-#include "clang/AST/DeclCXX.h"
-#include "clang/AST/DeclGroup.h"
-#include "clang/Frontend/FrontendAction.h"
 #include "clang/Tooling/CompilationDatabase.h"
 #include "clang/Tooling/FileMatchTrie.h"
 #include "clang/Tooling/JSONCompilationDatabase.h"
@@ -24,6 +21,8 @@
 
 using testing::ElementsAre;
 using testing::EndsWith;
+using testing::IsEmpty;
+using testing::UnorderedElementsAreArray;
 
 static void expectFailure(StringRef JSONDatabase, StringRef Explanation) {
   std::string ErrorMessage;
@@ -83,8 +82,8 @@
 
 TEST(JSONCompilationDatabase, GetAllFiles) {
   std::string ErrorMessage;
-  EXPECT_EQ(std::vector(),
-getAllFiles("[]", ErrorMessage, JSONCommandLineSyntax::Gnu))
+  EXPECT_THAT(getAllFiles("[]", ErrorMessage, JSONCommandLineSyntax::Gnu),
+  IsEmpty())
   << ErrorMessage;
 
   std::vector expected_files;
@@ -97,8 +96,7 @@
   expected_files.push_back(std::string(PathStorage.str()));
   llvm::sys::path::native("//net/file1", PathStorage);
   expected_files.push_back(std::string(PathStorage.str()));
-  EXPECT_EQ(expected_files,
-getAllFiles(R"json(
+  EXPECT_THAT(getAllFiles(R"json(
 [
   {
 "directory": "//net/dir",
@@ -121,7 +119,8 @@
 "file": "//net/dir/foo/../file3"
   }
 ])json",
-ErrorMessage, JSONCommandLineSyntax::Gnu))
+  ErrorMessage, JSONCommandLineSyntax::Gnu),
+  UnorderedElementsAreArray(expected_files))
   << ErrorMessage;
 }
 
@@ -550,7 +549,7 @@
   CommandLine.push_back("two");
   FixedCompilationDatabase Database(".", CommandLine);
 
-  EXPECT_EQ(0ul, Database.getAllFiles().size());
+  EXPECT_THAT(Database.getAllFiles(), IsEmpty());
 }
 
 TEST(FixedCompilationDatabase, GetAllCompileCommands) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157632: [Profile] Allow online merging with debug info correlation.

2023-08-22 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added inline comments.



Comment at: compiler-rt/lib/profile/InstrProfilingMerge.c:146
+if (!(__llvm_profile_get_version() & VARIANT_MASK_DBG_CORRELATE)) {
+  PROF_ERR("%s\n", "Missing profile data section.");
+  return 1;

aeubanks wrote:
> aeubanks wrote:
> > we're running into this error message even though we don't have debug info 
> > correlation turned on, is that expected in some configurations? I'm still 
> > trying to understand how we could end up in this code path without debug 
> > info correlation
> > 
> > https://crbug.com/1473935
> also it seems like this code path isn't tested?
It's very strange that you are hitting this code path because I didn't think it 
was possible. Were you ever able to reproduce locally?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157632/new/

https://reviews.llvm.org/D157632

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


[PATCH] D154014: [SpecialCaseList] Use Globs instead of Regex

2023-08-08 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 548349.
ellis added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154014/new/

https://reviews.llvm.org/D154014

Files:
  clang/docs/SanitizerSpecialCaseList.rst
  clang/lib/Basic/ProfileList.cpp
  clang/lib/Basic/SanitizerSpecialCaseList.cpp
  llvm/include/llvm/Support/SpecialCaseList.h
  llvm/lib/Support/SpecialCaseList.cpp
  llvm/unittests/Support/SpecialCaseListTest.cpp

Index: llvm/unittests/Support/SpecialCaseListTest.cpp
===
--- llvm/unittests/Support/SpecialCaseListTest.cpp
+++ llvm/unittests/Support/SpecialCaseListTest.cpp
@@ -10,8 +10,11 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/VirtualFileSystem.h"
+#include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
+using testing::HasSubstr;
+using testing::StartsWith;
 using namespace llvm;
 
 namespace {
@@ -19,24 +22,32 @@
 class SpecialCaseListTest : public ::testing::Test {
 protected:
   std::unique_ptr makeSpecialCaseList(StringRef List,
-   std::string &Error) {
-std::unique_ptr MB = MemoryBuffer::getMemBuffer(List);
+   std::string &Error,
+   bool UseGlobs = true) {
+auto S = List.str();
+if (UseGlobs)
+  S = (Twine("#!special-case-list-v2\n") + S).str();
+std::unique_ptr MB = MemoryBuffer::getMemBuffer(S);
 return SpecialCaseList::create(MB.get(), Error);
   }
 
-  std::unique_ptr makeSpecialCaseList(StringRef List) {
+  std::unique_ptr makeSpecialCaseList(StringRef List,
+   bool UseGlobs = true) {
 std::string Error;
-auto SCL = makeSpecialCaseList(List, Error);
+auto SCL = makeSpecialCaseList(List, Error, UseGlobs);
 assert(SCL);
 assert(Error == "");
 return SCL;
   }
 
-  std::string makeSpecialCaseListFile(StringRef Contents) {
+  std::string makeSpecialCaseListFile(StringRef Contents,
+  bool UseGlobs = true) {
 int FD;
 SmallString<64> Path;
 sys::fs::createTemporaryFile("SpecialCaseListTest", "temp", FD, Path);
 raw_fd_ostream OF(FD, true, true);
+if (UseGlobs)
+  OF << "#!special-case-list-v2\n";
 OF << Contents;
 OF.close();
 return std::string(Path.str());
@@ -59,10 +70,10 @@
   EXPECT_FALSE(SCL->inSection("", "fun", "hello"));
   EXPECT_FALSE(SCL->inSection("", "src", "hello", "category"));
 
-  EXPECT_EQ(3u, SCL->inSectionBlame("", "src", "hello"));
-  EXPECT_EQ(4u, SCL->inSectionBlame("", "src", "bye"));
-  EXPECT_EQ(5u, SCL->inSectionBlame("", "src", "hi", "category"));
-  EXPECT_EQ(6u, SCL->inSectionBlame("", "src", "", "category"));
+  EXPECT_EQ(4u, SCL->inSectionBlame("", "src", "hello"));
+  EXPECT_EQ(5u, SCL->inSectionBlame("", "src", "bye"));
+  EXPECT_EQ(6u, SCL->inSectionBlame("", "src", "hi", "category"));
+  EXPECT_EQ(7u, SCL->inSectionBlame("", "src", "", "category"));
   EXPECT_EQ(0u, SCL->inSectionBlame("", "src", "hi"));
   EXPECT_EQ(0u, SCL->inSectionBlame("", "fun", "hello"));
   EXPECT_EQ(0u, SCL->inSectionBlame("", "src", "hello", "category"));
@@ -74,31 +85,29 @@
  "\n"
  "[not valid\n",
  Error));
-  EXPECT_TRUE(
-  ((StringRef)Error).startswith("malformed section header on line 3:"));
+  EXPECT_THAT(Error, StartsWith("malformed section header on line 4:"));
 
   EXPECT_EQ(nullptr, makeSpecialCaseList("\n\n\n"
  "[not valid\n",
  Error));
-  EXPECT_TRUE(
-  ((StringRef)Error).startswith("malformed section header on line 4:"));
+  EXPECT_THAT(Error, StartsWith("malformed section header on line 5:"));
 }
 
-TEST_F(SpecialCaseListTest, SectionRegexErrorHandling) {
+TEST_F(SpecialCaseListTest, SectionGlobErrorHandling) {
   std::string Error;
   EXPECT_EQ(makeSpecialCaseList("[address", Error), nullptr);
-  EXPECT_TRUE(((StringRef)Error).startswith("malformed section header "));
+  EXPECT_THAT(Error, StartsWith("malformed section header "));
 
   EXPECT_EQ(makeSpecialCaseList("[[]", Error), nullptr);
-  EXPECT_TRUE(((StringRef)Error).startswith("malformed regex for section [: "));
+  EXPECT_EQ(Error, "malformed section at line 2: '[': invalid glob pattern: [");
 
   EXPECT_EQ(makeSpecialCaseList("src:=", Error), nullptr);
-  EXPECT_TRUE(((StringRef)Error).endswith("Supplied regexp was blank"));
+  EXPECT_THAT(Error, HasSubstr("Supplied glob was blank"));
 }
 
 TEST_F(SpecialCaseListTest, Section) {
   std::unique_ptr SCL = makeSpecialCaseList("src:global\n"
- "[sect1|sect2]\n"
+

[PATCH] D154014: [SpecialCaseList] Use Globs instead of Regex

2023-08-09 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 548693.
ellis added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154014/new/

https://reviews.llvm.org/D154014

Files:
  clang/docs/SanitizerSpecialCaseList.rst
  clang/lib/Basic/ProfileList.cpp
  clang/lib/Basic/SanitizerSpecialCaseList.cpp
  llvm/include/llvm/Support/SpecialCaseList.h
  llvm/lib/Support/SpecialCaseList.cpp
  llvm/unittests/Support/SpecialCaseListTest.cpp

Index: llvm/unittests/Support/SpecialCaseListTest.cpp
===
--- llvm/unittests/Support/SpecialCaseListTest.cpp
+++ llvm/unittests/Support/SpecialCaseListTest.cpp
@@ -10,8 +10,11 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/VirtualFileSystem.h"
+#include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
+using testing::HasSubstr;
+using testing::StartsWith;
 using namespace llvm;
 
 namespace {
@@ -19,24 +22,32 @@
 class SpecialCaseListTest : public ::testing::Test {
 protected:
   std::unique_ptr makeSpecialCaseList(StringRef List,
-   std::string &Error) {
-std::unique_ptr MB = MemoryBuffer::getMemBuffer(List);
+   std::string &Error,
+   bool UseGlobs = true) {
+auto S = List.str();
+if (UseGlobs)
+  S = (Twine("#!special-case-list-v2\n") + S).str();
+std::unique_ptr MB = MemoryBuffer::getMemBuffer(S);
 return SpecialCaseList::create(MB.get(), Error);
   }
 
-  std::unique_ptr makeSpecialCaseList(StringRef List) {
+  std::unique_ptr makeSpecialCaseList(StringRef List,
+   bool UseGlobs = true) {
 std::string Error;
-auto SCL = makeSpecialCaseList(List, Error);
+auto SCL = makeSpecialCaseList(List, Error, UseGlobs);
 assert(SCL);
 assert(Error == "");
 return SCL;
   }
 
-  std::string makeSpecialCaseListFile(StringRef Contents) {
+  std::string makeSpecialCaseListFile(StringRef Contents,
+  bool UseGlobs = true) {
 int FD;
 SmallString<64> Path;
 sys::fs::createTemporaryFile("SpecialCaseListTest", "temp", FD, Path);
 raw_fd_ostream OF(FD, true, true);
+if (UseGlobs)
+  OF << "#!special-case-list-v2\n";
 OF << Contents;
 OF.close();
 return std::string(Path.str());
@@ -59,10 +70,10 @@
   EXPECT_FALSE(SCL->inSection("", "fun", "hello"));
   EXPECT_FALSE(SCL->inSection("", "src", "hello", "category"));
 
-  EXPECT_EQ(3u, SCL->inSectionBlame("", "src", "hello"));
-  EXPECT_EQ(4u, SCL->inSectionBlame("", "src", "bye"));
-  EXPECT_EQ(5u, SCL->inSectionBlame("", "src", "hi", "category"));
-  EXPECT_EQ(6u, SCL->inSectionBlame("", "src", "", "category"));
+  EXPECT_EQ(4u, SCL->inSectionBlame("", "src", "hello"));
+  EXPECT_EQ(5u, SCL->inSectionBlame("", "src", "bye"));
+  EXPECT_EQ(6u, SCL->inSectionBlame("", "src", "hi", "category"));
+  EXPECT_EQ(7u, SCL->inSectionBlame("", "src", "", "category"));
   EXPECT_EQ(0u, SCL->inSectionBlame("", "src", "hi"));
   EXPECT_EQ(0u, SCL->inSectionBlame("", "fun", "hello"));
   EXPECT_EQ(0u, SCL->inSectionBlame("", "src", "hello", "category"));
@@ -74,31 +85,31 @@
  "\n"
  "[not valid\n",
  Error));
-  EXPECT_TRUE(
-  ((StringRef)Error).startswith("malformed section header on line 3:"));
+  EXPECT_THAT(Error, StartsWith("malformed section header on line 4:"));
 
   EXPECT_EQ(nullptr, makeSpecialCaseList("\n\n\n"
  "[not valid\n",
  Error));
-  EXPECT_TRUE(
-  ((StringRef)Error).startswith("malformed section header on line 4:"));
+  EXPECT_THAT(Error, StartsWith("malformed section header on line 5:"));
 }
 
-TEST_F(SpecialCaseListTest, SectionRegexErrorHandling) {
+TEST_F(SpecialCaseListTest, SectionGlobErrorHandling) {
   std::string Error;
   EXPECT_EQ(makeSpecialCaseList("[address", Error), nullptr);
-  EXPECT_TRUE(((StringRef)Error).startswith("malformed section header "));
+  EXPECT_THAT(Error, StartsWith("malformed section header "));
 
   EXPECT_EQ(makeSpecialCaseList("[[]", Error), nullptr);
-  EXPECT_TRUE(((StringRef)Error).startswith("malformed regex for section [: "));
+  EXPECT_EQ(
+  Error,
+  "malformed section at line 2: '[': invalid glob pattern, unmatched '['");
 
   EXPECT_EQ(makeSpecialCaseList("src:=", Error), nullptr);
-  EXPECT_TRUE(((StringRef)Error).endswith("Supplied regexp was blank"));
+  EXPECT_THAT(Error, HasSubstr("Supplied glob was blank"));
 }
 
 TEST_F(SpecialCaseListTest, Section) {
   std::unique_ptr SCL = makeSpecialCaseList("src:global\n"
- "[sect1|sect

[PATCH] D157913: [Coverage] Allow Clang coverage to be used with debug info correlation.

2023-09-12 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added a comment.

In D157913#4638845 , @zequanwu wrote:

> In D157913#4638569 , @phosek wrote:
>
>> In D157913#4626007 , @zequanwu 
>> wrote:
>>
 It seems that the `__llvm_prf_names` is retained in this mode. What is the 
 overhead of this section generally? Can we instead use debug info to 
 lookup function names?
>>>
>>> With debug info correlation enabled, `__llvm_prf_names` section will only 
>>> contain functions names that are not emitted to the final binary, not even 
>>> in debug info.
>>
>> Could we emit those names into the `.debug_str` section?
>
> Yes, I think it's feasible by creating a fake variable debug info that 
> contains all the skipped function names in the source file for each object 
> file, but that's a bit more overhead in debug info compared to just plain 
> `__llvm_prf_names` in binary, which is only about 0.2% or less of original 
> size [1].
>
> [1]: https://bugs.chromium.org/p/chromium/issues/detail?id=1463755#c8

Since the `.debug_str` section can be stripped before execution time, I don't 
count that towards the binary size overhead. But I believe the 
`__llvm_prf_names` section cannot be stripped as is. So it would be an 
improvement if we could completely remove the `__llvm_prf_names` section and 
emit names in the `.debug_str` section.

I see that you have one case where the overhead of the names section is just 
0.2%. I wonder if this is common or if there exist real-world scenarios where 
the overhead is more significant. If not then leaving the names section in the 
binary might be ok, but we should probably leave a note explaining how we could 
remove it if we emit the names in debug info.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157913/new/

https://reviews.llvm.org/D157913

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


[PATCH] D157913: [Coverage] Allow Clang coverage to be used with debug info correlation.

2023-09-14 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added a comment.

It looks like `debug-info-correlate-coverage.ll` was renamed twice. Is this 
intended?




Comment at: compiler-rt/lib/profile/InstrProfilingWriter.c:276-277
   __llvm_profile_get_num_counters(CountersBegin, CountersEnd);
-  const uint64_t NamesSize = DebugInfoCorrelate ? 0 : NamesEnd - NamesBegin;
+  const uint64_t NamesSize =
+  DebugInfoCorrelate && IRLevelProfile ? 0 : NamesEnd - NamesBegin;
 

Can we remove changes to this file now that we are stripping the names section?



Comment at: llvm/lib/ProfileData/InstrProfCorrelator.cpp:423
+  }
+  return;
+}

I think this return should be on the line above to break out of the for loop 
early. Or did I miscount the brackets?



Comment at: llvm/lib/ProfileData/InstrProfReader.cpp:577-578
 // Correlator.
-assert(DataSize == 0 && NamesSize == 0);
-assert(CountersDelta == 0 && NamesDelta == 0);
+assert(DataSize == 0 && (!isIRLevelProfile() || NamesSize == 0));
+assert(CountersDelta == 0 && (!isIRLevelProfile() || NamesDelta == 0));
 Data = Correlator->getDataPointer();

I think these changes can also be removed



Comment at: llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp:769
   }
+  if (DebugInfoCorrelate && !ReferencedNames.empty()) {
+MDNode *Node = *M->debug_compile_units_begin();

Just so that I understand. Does this code run only for names of unused 
functions? Or will we store all function names with `CovFunctionNameAnnotation`?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157913/new/

https://reviews.llvm.org/D157913

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


[PATCH] D157913: [Coverage] Allow Clang coverage to be used with debug info correlation.

2023-09-14 Thread Ellis Hoag via Phabricator via cfe-commits
ellis accepted this revision.
ellis added a comment.
This revision is now accepted and ready to land.

In D157913#4646201 , @zequanwu wrote:

> In D157913#4646184 , @ellis wrote:
>
>> It looks like `debug-info-correlate-coverage.ll` was renamed twice. Is this 
>> intended?
>
> I just moved 
> `llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-coverage.ll.` 
> to 
> `llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-byte-coverage.ll`
>  and created a new test file 
> `llvm/test/Instrumentation/InstrProfiling/debug-info-correlate-clang-coverage.ll.`

Got it! Sorry I got confused by the UI.

Sounds good to me! I'm excited to see clang instrumentation can take full 
advantage of debug info correlation!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157913/new/

https://reviews.llvm.org/D157913

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


[PATCH] D159000: Reland "[Profile] Allow online merging with debug info correlation."

2023-08-28 Thread Ellis Hoag via Phabricator via cfe-commits
ellis accepted this revision.
ellis added a comment.
This revision is now accepted and ready to land.

Thanks for adding the test case! Can you also link the original diff in the 
summary?




Comment at: compiler-rt/test/profile/instrprof-merge-empty-data.test:1
+// Test 
+// RUN: rm -rf %t.dir && split-file %s %t.dir && cd %t.dir

Please add a more descriptive explanation for this test 😜


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159000/new/

https://reviews.llvm.org/D159000

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


[PATCH] D154014: [SpecialCaseList] Use Globs instead of Regex

2023-08-28 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 554089.
ellis added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154014/new/

https://reviews.llvm.org/D154014

Files:
  clang/docs/SanitizerSpecialCaseList.rst
  clang/lib/Basic/ProfileList.cpp
  clang/lib/Basic/SanitizerSpecialCaseList.cpp
  llvm/include/llvm/Support/SpecialCaseList.h
  llvm/lib/Support/SpecialCaseList.cpp
  llvm/unittests/Support/SpecialCaseListTest.cpp

Index: llvm/unittests/Support/SpecialCaseListTest.cpp
===
--- llvm/unittests/Support/SpecialCaseListTest.cpp
+++ llvm/unittests/Support/SpecialCaseListTest.cpp
@@ -10,8 +10,11 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/VirtualFileSystem.h"
+#include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
+using testing::HasSubstr;
+using testing::StartsWith;
 using namespace llvm;
 
 namespace {
@@ -19,24 +22,32 @@
 class SpecialCaseListTest : public ::testing::Test {
 protected:
   std::unique_ptr makeSpecialCaseList(StringRef List,
-   std::string &Error) {
-std::unique_ptr MB = MemoryBuffer::getMemBuffer(List);
+   std::string &Error,
+   bool UseGlobs = true) {
+auto S = List.str();
+if (UseGlobs)
+  S = (Twine("#!special-case-list-v2\n") + S).str();
+std::unique_ptr MB = MemoryBuffer::getMemBuffer(S);
 return SpecialCaseList::create(MB.get(), Error);
   }
 
-  std::unique_ptr makeSpecialCaseList(StringRef List) {
+  std::unique_ptr makeSpecialCaseList(StringRef List,
+   bool UseGlobs = true) {
 std::string Error;
-auto SCL = makeSpecialCaseList(List, Error);
+auto SCL = makeSpecialCaseList(List, Error, UseGlobs);
 assert(SCL);
 assert(Error == "");
 return SCL;
   }
 
-  std::string makeSpecialCaseListFile(StringRef Contents) {
+  std::string makeSpecialCaseListFile(StringRef Contents,
+  bool UseGlobs = true) {
 int FD;
 SmallString<64> Path;
 sys::fs::createTemporaryFile("SpecialCaseListTest", "temp", FD, Path);
 raw_fd_ostream OF(FD, true, true);
+if (UseGlobs)
+  OF << "#!special-case-list-v2\n";
 OF << Contents;
 OF.close();
 return std::string(Path.str());
@@ -59,10 +70,10 @@
   EXPECT_FALSE(SCL->inSection("", "fun", "hello"));
   EXPECT_FALSE(SCL->inSection("", "src", "hello", "category"));
 
-  EXPECT_EQ(3u, SCL->inSectionBlame("", "src", "hello"));
-  EXPECT_EQ(4u, SCL->inSectionBlame("", "src", "bye"));
-  EXPECT_EQ(5u, SCL->inSectionBlame("", "src", "hi", "category"));
-  EXPECT_EQ(6u, SCL->inSectionBlame("", "src", "", "category"));
+  EXPECT_EQ(4u, SCL->inSectionBlame("", "src", "hello"));
+  EXPECT_EQ(5u, SCL->inSectionBlame("", "src", "bye"));
+  EXPECT_EQ(6u, SCL->inSectionBlame("", "src", "hi", "category"));
+  EXPECT_EQ(7u, SCL->inSectionBlame("", "src", "", "category"));
   EXPECT_EQ(0u, SCL->inSectionBlame("", "src", "hi"));
   EXPECT_EQ(0u, SCL->inSectionBlame("", "fun", "hello"));
   EXPECT_EQ(0u, SCL->inSectionBlame("", "src", "hello", "category"));
@@ -74,31 +85,31 @@
  "\n"
  "[not valid\n",
  Error));
-  EXPECT_TRUE(
-  ((StringRef)Error).startswith("malformed section header on line 3:"));
+  EXPECT_THAT(Error, StartsWith("malformed section header on line 4:"));
 
   EXPECT_EQ(nullptr, makeSpecialCaseList("\n\n\n"
  "[not valid\n",
  Error));
-  EXPECT_TRUE(
-  ((StringRef)Error).startswith("malformed section header on line 4:"));
+  EXPECT_THAT(Error, StartsWith("malformed section header on line 5:"));
 }
 
-TEST_F(SpecialCaseListTest, SectionRegexErrorHandling) {
+TEST_F(SpecialCaseListTest, SectionGlobErrorHandling) {
   std::string Error;
   EXPECT_EQ(makeSpecialCaseList("[address", Error), nullptr);
-  EXPECT_TRUE(((StringRef)Error).startswith("malformed section header "));
+  EXPECT_THAT(Error, StartsWith("malformed section header "));
 
   EXPECT_EQ(makeSpecialCaseList("[[]", Error), nullptr);
-  EXPECT_TRUE(((StringRef)Error).startswith("malformed regex for section [: "));
+  EXPECT_EQ(
+  Error,
+  "malformed section at line 2: '[': invalid glob pattern, unmatched '['");
 
   EXPECT_EQ(makeSpecialCaseList("src:=", Error), nullptr);
-  EXPECT_TRUE(((StringRef)Error).endswith("Supplied regexp was blank"));
+  EXPECT_THAT(Error, HasSubstr("Supplied glob was blank"));
 }
 
 TEST_F(SpecialCaseListTest, Section) {
   std::unique_ptr SCL = makeSpecialCaseList("src:global\n"
- "[sect1|sect

[PATCH] D157913: [Coverage] Allow Clang coverage to be used with debug info correlation.

2023-08-29 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added a comment.

Thanks for working on this! I've added a few other reviewers that might be 
interested. In particular it might conflict with the stack D138846 
 IIRC
It seems that the `__llvm_prf_names` is retained in this mode. What is the 
overhead of this section generally? Can we instead use debug info to lookup 
function names?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157913/new/

https://reviews.llvm.org/D157913

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


[PATCH] D154014: [SpecialCaseList] Add option to use Globs instead of Regex to match patterns

2023-09-01 Thread Ellis Hoag via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8eb34700c2b1: [SpecialCaseList] Add option to use Globs 
instead of Regex to match patterns (authored by ellis).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154014/new/

https://reviews.llvm.org/D154014

Files:
  clang/docs/SanitizerSpecialCaseList.rst
  clang/lib/Basic/ProfileList.cpp
  clang/lib/Basic/SanitizerSpecialCaseList.cpp
  llvm/include/llvm/Support/SpecialCaseList.h
  llvm/lib/Support/SpecialCaseList.cpp
  llvm/unittests/Support/SpecialCaseListTest.cpp

Index: llvm/unittests/Support/SpecialCaseListTest.cpp
===
--- llvm/unittests/Support/SpecialCaseListTest.cpp
+++ llvm/unittests/Support/SpecialCaseListTest.cpp
@@ -10,8 +10,11 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/VirtualFileSystem.h"
+#include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
+using testing::HasSubstr;
+using testing::StartsWith;
 using namespace llvm;
 
 namespace {
@@ -19,24 +22,32 @@
 class SpecialCaseListTest : public ::testing::Test {
 protected:
   std::unique_ptr makeSpecialCaseList(StringRef List,
-   std::string &Error) {
-std::unique_ptr MB = MemoryBuffer::getMemBuffer(List);
+   std::string &Error,
+   bool UseGlobs = true) {
+auto S = List.str();
+if (UseGlobs)
+  S = (Twine("#!special-case-list-v2\n") + S).str();
+std::unique_ptr MB = MemoryBuffer::getMemBuffer(S);
 return SpecialCaseList::create(MB.get(), Error);
   }
 
-  std::unique_ptr makeSpecialCaseList(StringRef List) {
+  std::unique_ptr makeSpecialCaseList(StringRef List,
+   bool UseGlobs = true) {
 std::string Error;
-auto SCL = makeSpecialCaseList(List, Error);
+auto SCL = makeSpecialCaseList(List, Error, UseGlobs);
 assert(SCL);
 assert(Error == "");
 return SCL;
   }
 
-  std::string makeSpecialCaseListFile(StringRef Contents) {
+  std::string makeSpecialCaseListFile(StringRef Contents,
+  bool UseGlobs = true) {
 int FD;
 SmallString<64> Path;
 sys::fs::createTemporaryFile("SpecialCaseListTest", "temp", FD, Path);
 raw_fd_ostream OF(FD, true, true);
+if (UseGlobs)
+  OF << "#!special-case-list-v2\n";
 OF << Contents;
 OF.close();
 return std::string(Path.str());
@@ -59,10 +70,10 @@
   EXPECT_FALSE(SCL->inSection("", "fun", "hello"));
   EXPECT_FALSE(SCL->inSection("", "src", "hello", "category"));
 
-  EXPECT_EQ(3u, SCL->inSectionBlame("", "src", "hello"));
-  EXPECT_EQ(4u, SCL->inSectionBlame("", "src", "bye"));
-  EXPECT_EQ(5u, SCL->inSectionBlame("", "src", "hi", "category"));
-  EXPECT_EQ(6u, SCL->inSectionBlame("", "src", "", "category"));
+  EXPECT_EQ(4u, SCL->inSectionBlame("", "src", "hello"));
+  EXPECT_EQ(5u, SCL->inSectionBlame("", "src", "bye"));
+  EXPECT_EQ(6u, SCL->inSectionBlame("", "src", "hi", "category"));
+  EXPECT_EQ(7u, SCL->inSectionBlame("", "src", "", "category"));
   EXPECT_EQ(0u, SCL->inSectionBlame("", "src", "hi"));
   EXPECT_EQ(0u, SCL->inSectionBlame("", "fun", "hello"));
   EXPECT_EQ(0u, SCL->inSectionBlame("", "src", "hello", "category"));
@@ -74,31 +85,31 @@
  "\n"
  "[not valid\n",
  Error));
-  EXPECT_TRUE(
-  ((StringRef)Error).startswith("malformed section header on line 3:"));
+  EXPECT_THAT(Error, StartsWith("malformed section header on line 4:"));
 
   EXPECT_EQ(nullptr, makeSpecialCaseList("\n\n\n"
  "[not valid\n",
  Error));
-  EXPECT_TRUE(
-  ((StringRef)Error).startswith("malformed section header on line 4:"));
+  EXPECT_THAT(Error, StartsWith("malformed section header on line 5:"));
 }
 
-TEST_F(SpecialCaseListTest, SectionRegexErrorHandling) {
+TEST_F(SpecialCaseListTest, SectionGlobErrorHandling) {
   std::string Error;
   EXPECT_EQ(makeSpecialCaseList("[address", Error), nullptr);
-  EXPECT_TRUE(((StringRef)Error).startswith("malformed section header "));
+  EXPECT_THAT(Error, StartsWith("malformed section header "));
 
   EXPECT_EQ(makeSpecialCaseList("[[]", Error), nullptr);
-  EXPECT_TRUE(((StringRef)Error).startswith("malformed regex for section [: "));
+  EXPECT_EQ(
+  Error,
+  "malformed section at line 2: '[': invalid glob pattern, unmatched '['");
 
   EXPECT_EQ(makeSpecialCaseList("src:=", Error), nullptr);
-  EXPECT_TRUE(((StringRef)Error).endswith("Supplied regexp was blank"));
+  EXPECT_THAT(Error, HasSubstr("Supplied glob was bla

[PATCH] D157913: [Coverage] Allow Clang coverage to be used with debug info correlation.

2023-09-01 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added a comment.

In D157913#4626007 , @zequanwu wrote:

>> It seems that the `__llvm_prf_names` is retained in this mode. What is the 
>> overhead of this section generally? Can we instead use debug info to lookup 
>> function names?
>
> With debug info correlation enabled, `__llvm_prf_names` section will only 
> contain functions names that are not emitted to the final binary, not even in 
> debug info. So, this section is still much smaller compared to when not 
> enabling debug info correlation. This is used to indicate that those 
> functions are covered but not executed.
>
> Example from the test case above:
>
>   $ cat a.cpp
>   struct A {
> void unused_func() {}
>   };
>   void used_func() {}
>   int main() {
> used_func();
> return 0;
>   }
>   $ clang -fprofile-instr-generate -fcoverage-mapping -mllvm 
> -enable-name-compression=false -mllvm -debug-info-correlate -g a.cpp -o a.out
>   $ llvm-objdump --section=__llvm_prf_names --full-contents a.out
>   
>   a.out:  file format elf64-x86-64
>   Contents of section __llvm_prf_names:
>7b65 14005f5a 4e314131 31756e75 7365645f  .._ZN1A11unused_
>7b75 66756e63 4576funcEv

Thanks for the explanation!




Comment at: clang/test/CodeGen/coverage-debug-info-correlate.c:1
+// RUN: %clang_cc1 -debug-info-kind=standalone -mllvm -debug-info-correlate 
-fprofile-instrument=clang -fcoverage-mapping -emit-llvm -o - %s | FileCheck %s
+

I think this test can be generalized to check that `__llvm_profile_raw_version` 
is emitted with or without debug info correlation.



Comment at: compiler-rt/test/profile/Darwin/coverage-debug-info-correlate.cpp:9
+// RUN: %clang_profgen -o %t -g -mllvm --debug-info-correlate 
-fcoverage-mapping %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
+// RUN: llvm-profdata merge -o %t.profdata --debug-info=%t.dSYM %t.profraw

NIT



Comment at: compiler-rt/test/profile/Darwin/coverage-debug-info-correlate.cpp:29
+
+// RUN: llvm-cov report --instr-profile=%t.profdata %t | FileCheck %s 
-check-prefix=NONAME
+

Is it worth testing that `%t.normal.profdata` emits the same coverage?



Comment at: llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp:1019-1029
+  if (auto E = NamesSection.takeError()) {
+if (ProfileNames.isEmpty())
+  return std::move(E);
+consumeError(std::move(E));
+  } else {
+std::vector NamesSectionRefs = *NamesSection;
+if (NamesSectionRefs.size() != 1)

I don't quite understand why this was changed. Is there is a test case that 
covers this?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157913/new/

https://reviews.llvm.org/D157913

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


[PATCH] D152762: [clang][docs] Update SanitizerSpecialCaseList docs

2023-06-28 Thread Ellis Hoag via Phabricator via cfe-commits
ellis abandoned this revision.
ellis added a comment.

Moved to https://reviews.llvm.org/D154014


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152762/new/

https://reviews.llvm.org/D152762

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


[PATCH] D154014: [SpecialCaseList] Use Globs instead of Regex

2023-06-28 Thread Ellis Hoag via Phabricator via cfe-commits
ellis created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
ellis edited the summary of this revision.
ellis added reviewers: MaskRay, phosek, vitalybuka, samsonov, hctim.
ellis updated this revision to Diff 535560.
ellis added a comment.
ellis published this revision for review.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Fix ProfileList


Switch `SpecialCaseList` from using Regex to Globs to match patterns. 
`GlobPattern` was extended in https://reviews.llvm.org/D153587 to support brace 
expansions which allows us to use patterns like `*/src/foo.{c,cpp}`. It turns 
out that most patterns only use `*` to match any string and a few special cases 
use brace expansions, so using Regex was overkill and required lots of escaping 
in practice.

This is a breaking change since some SCLs might use `.*` or `(abc|def)` which 
are supported regexes but not valid globs. Since we have just cut clang 16.x 
this is a good time to make this change.

See discussion in https://reviews.llvm.org/D152762


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154014

Files:
  clang/docs/SanitizerSpecialCaseList.rst
  clang/lib/Basic/ProfileList.cpp
  clang/lib/Basic/SanitizerSpecialCaseList.cpp
  llvm/include/llvm/Support/SpecialCaseList.h
  llvm/lib/Support/SpecialCaseList.cpp
  llvm/unittests/Support/SpecialCaseListTest.cpp

Index: llvm/unittests/Support/SpecialCaseListTest.cpp
===
--- llvm/unittests/Support/SpecialCaseListTest.cpp
+++ llvm/unittests/Support/SpecialCaseListTest.cpp
@@ -10,8 +10,11 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/VirtualFileSystem.h"
+#include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
+using testing::HasSubstr;
+using testing::StartsWith;
 using namespace llvm;
 
 namespace {
@@ -50,7 +53,8 @@
   "src:hello\n"
   "src:bye\n"
   "src:hi=category\n"
-  "src:z*=category\n");
+  "src:z*=category\n"
+  " \n");
   EXPECT_TRUE(SCL->inSection("", "src", "hello"));
   EXPECT_TRUE(SCL->inSection("", "src", "bye"));
   EXPECT_TRUE(SCL->inSection("", "src", "hi", "category"));
@@ -74,31 +78,29 @@
  "\n"
  "[not valid\n",
  Error));
-  EXPECT_TRUE(
-  ((StringRef)Error).startswith("malformed section header on line 3:"));
+  EXPECT_THAT(Error, StartsWith("malformed section header on line 3:"));
 
   EXPECT_EQ(nullptr, makeSpecialCaseList("\n\n\n"
  "[not valid\n",
  Error));
-  EXPECT_TRUE(
-  ((StringRef)Error).startswith("malformed section header on line 4:"));
+  EXPECT_THAT(Error, StartsWith("malformed section header on line 4:"));
 }
 
-TEST_F(SpecialCaseListTest, SectionRegexErrorHandling) {
+TEST_F(SpecialCaseListTest, SectionGlobErrorHandling) {
   std::string Error;
   EXPECT_EQ(makeSpecialCaseList("[address", Error), nullptr);
-  EXPECT_TRUE(((StringRef)Error).startswith("malformed section header "));
+  EXPECT_THAT(Error, StartsWith("malformed section header "));
 
   EXPECT_EQ(makeSpecialCaseList("[[]", Error), nullptr);
-  EXPECT_TRUE(((StringRef)Error).startswith("malformed regex for section [: "));
+  EXPECT_EQ(Error, "malformed section at line 1: '[': invalid glob pattern: [");
 
   EXPECT_EQ(makeSpecialCaseList("src:=", Error), nullptr);
-  EXPECT_TRUE(((StringRef)Error).endswith("Supplied regexp was blank"));
+  EXPECT_THAT(Error, HasSubstr("Supplied glob was blank"));
 }
 
 TEST_F(SpecialCaseListTest, Section) {
   std::unique_ptr SCL = makeSpecialCaseList("src:global\n"
- "[sect1|sect2]\n"
+ "[{sect1,sect2}]\n"
  "src:test1\n"
  "[sect3*]\n"
  "src:test2\n");
@@ -154,17 +156,12 @@
   EXPECT_EQ(nullptr, makeSpecialCaseList("badline", Error));
   EXPECT_EQ("malformed line 1: 'badline'", Error);
   EXPECT_EQ(nullptr, makeSpecialCaseList("src:bad[a-", Error));
-  EXPECT_EQ("malformed regex in line 1: 'bad[a-': invalid character range",
-Error);
-  EXPECT_EQ(nullptr, makeSpecialCaseList("src:a.c\n"
-   "fun:fun(a\n",
-   Error));
-  EXPECT_EQ("malformed regex in line 2: 'fun(a': parentheses not balanced",
+  EXPECT_EQ("malformed glob in line 1: 'bad[a-': invalid glob pattern: bad[a-",
 Error);
   std::vector Files(1, "unexisting");
   EXPECT_EQ(nullptr,

[PATCH] D154014: [SpecialCaseList] Use Globs instead of Regex

2023-06-29 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added a comment.

In D154014#4461076 , @rupprecht wrote:

> In D154014#4457883 , @MaskRay wrote:
>
>>> This is a breaking change since some SCLs might use .* or (abc|def) which 
>>> are supported regexes but not valid globs. Since we have just cut clang 
>>> 16.x this is a good time to make this change.
>>
>> My user has some ignore lists, but there is no `^[a-z]+:.*\(` or 
>> `^[a-z]+:\.` occurrence, so this change is likely safe for us.
>
> I think I'm looking at the same lists, and I see plenty of `.*` in the 
> sanitizer exclusion lists. Also a few cases of `(abc|def|...)`. IIUC, those 
> would both be broken by this -- instead of `.*` meaning "any character any 
> number of times" (regex) it would mean "dot followed by any number of 
> characters" (glob), right? And the `(abc|...)` would just be that literal 
> text, not matching the individual parts?
>
> If my understanding of that is correct, I don't think this is a good change 
> -- there's possibly plenty of configs out there that assume this is regex, 
> and there doesn't seem to be sufficient motivation to just break those. But I 
> can see that globs are useful for the examples posted in the patch 
> description. Is it possible to have some middle ground, e.g. default to regex 
> but allow a config at the top of sanitizer lists to interpret future patterns 
> as globs instead?

If a sanitizer list currently has `.*` it will be replaced with `..*` here 

 meaning that it matches one or more characters, so those lists may already be 
broken. This is exactly the confusion we would like to avoid. And you are 
correct that `(abc|def)` will be treated as a literal with this change, the but 
fix to `{abc,def}` is trivial.

That's a nice idea to add a config at the top to specify glob or regex to give 
users more time to migrate their lists.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154014/new/

https://reviews.llvm.org/D154014

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


[PATCH] D154014: [SpecialCaseList] Use Globs instead of Regex

2023-06-29 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 536003.
ellis added a comment.

Fix memory bug and add TODO about a regex/glob config. Lets wait for others to 
comment before I put work into this.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154014/new/

https://reviews.llvm.org/D154014

Files:
  clang/docs/SanitizerSpecialCaseList.rst
  clang/lib/Basic/ProfileList.cpp
  clang/lib/Basic/SanitizerSpecialCaseList.cpp
  llvm/include/llvm/Support/SpecialCaseList.h
  llvm/lib/Support/SpecialCaseList.cpp
  llvm/unittests/Support/SpecialCaseListTest.cpp

Index: llvm/unittests/Support/SpecialCaseListTest.cpp
===
--- llvm/unittests/Support/SpecialCaseListTest.cpp
+++ llvm/unittests/Support/SpecialCaseListTest.cpp
@@ -10,8 +10,11 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/VirtualFileSystem.h"
+#include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
+using testing::HasSubstr;
+using testing::StartsWith;
 using namespace llvm;
 
 namespace {
@@ -50,7 +53,8 @@
   "src:hello\n"
   "src:bye\n"
   "src:hi=category\n"
-  "src:z*=category\n");
+  "src:z*=category\n"
+  " \n");
   EXPECT_TRUE(SCL->inSection("", "src", "hello"));
   EXPECT_TRUE(SCL->inSection("", "src", "bye"));
   EXPECT_TRUE(SCL->inSection("", "src", "hi", "category"));
@@ -74,31 +78,29 @@
  "\n"
  "[not valid\n",
  Error));
-  EXPECT_TRUE(
-  ((StringRef)Error).startswith("malformed section header on line 3:"));
+  EXPECT_THAT(Error, StartsWith("malformed section header on line 3:"));
 
   EXPECT_EQ(nullptr, makeSpecialCaseList("\n\n\n"
  "[not valid\n",
  Error));
-  EXPECT_TRUE(
-  ((StringRef)Error).startswith("malformed section header on line 4:"));
+  EXPECT_THAT(Error, StartsWith("malformed section header on line 4:"));
 }
 
-TEST_F(SpecialCaseListTest, SectionRegexErrorHandling) {
+TEST_F(SpecialCaseListTest, SectionGlobErrorHandling) {
   std::string Error;
   EXPECT_EQ(makeSpecialCaseList("[address", Error), nullptr);
-  EXPECT_TRUE(((StringRef)Error).startswith("malformed section header "));
+  EXPECT_THAT(Error, StartsWith("malformed section header "));
 
   EXPECT_EQ(makeSpecialCaseList("[[]", Error), nullptr);
-  EXPECT_TRUE(((StringRef)Error).startswith("malformed regex for section [: "));
+  EXPECT_EQ(Error, "malformed section at line 1: '[': invalid glob pattern: [");
 
   EXPECT_EQ(makeSpecialCaseList("src:=", Error), nullptr);
-  EXPECT_TRUE(((StringRef)Error).endswith("Supplied regexp was blank"));
+  EXPECT_THAT(Error, HasSubstr("Supplied glob was blank"));
 }
 
 TEST_F(SpecialCaseListTest, Section) {
   std::unique_ptr SCL = makeSpecialCaseList("src:global\n"
- "[sect1|sect2]\n"
+ "[{sect1,sect2}]\n"
  "src:test1\n"
  "[sect3*]\n"
  "src:test2\n");
@@ -154,17 +156,12 @@
   EXPECT_EQ(nullptr, makeSpecialCaseList("badline", Error));
   EXPECT_EQ("malformed line 1: 'badline'", Error);
   EXPECT_EQ(nullptr, makeSpecialCaseList("src:bad[a-", Error));
-  EXPECT_EQ("malformed regex in line 1: 'bad[a-': invalid character range",
-Error);
-  EXPECT_EQ(nullptr, makeSpecialCaseList("src:a.c\n"
-   "fun:fun(a\n",
-   Error));
-  EXPECT_EQ("malformed regex in line 2: 'fun(a': parentheses not balanced",
+  EXPECT_EQ("malformed glob in line 1: 'bad[a-': invalid glob pattern: bad[a-",
 Error);
   std::vector Files(1, "unexisting");
   EXPECT_EQ(nullptr,
 SpecialCaseList::create(Files, *vfs::getRealFileSystem(), Error));
-  EXPECT_EQ(0U, Error.find("can't open file 'unexisting':"));
+  EXPECT_THAT(Error, StartsWith("can't open file 'unexisting':"));
 }
 
 TEST_F(SpecialCaseListTest, EmptySpecialCaseList) {
@@ -191,7 +188,7 @@
 }
 
 TEST_F(SpecialCaseListTest, NoTrigramsInRules) {
-  std::unique_ptr SCL = makeSpecialCaseList("fun:b.r\n"
+  std::unique_ptr SCL = makeSpecialCaseList("fun:b?r\n"
  "fun:za*az\n");
   EXPECT_TRUE(SCL->inSection("", "fun", "bar"));
   EXPECT_FALSE(SCL->inSection("", "fun", "baz"));
Index: llvm/lib/Support/SpecialCaseList.cpp
===
--- llvm/lib/Support/SpecialCaseList.cpp
+++ llvm/lib/Support/SpecialCaseList.cpp

[PATCH] D154014: [SpecialCaseList] Use Globs instead of Regex

2023-06-30 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added a comment.

In D154014#4462886 , @MaskRay wrote:

> In D154014#4461076 , @rupprecht 
> wrote:
>
>> In D154014#4457883 , @MaskRay 
>> wrote:
>>
 This is a breaking change since some SCLs might use .* or (abc|def) which 
 are supported regexes but not valid globs. Since we have just cut clang 
 16.x this is a good time to make this change.
>>>
>>> My user has some ignore lists, but there is no `^[a-z]+:.*\(` or 
>>> `^[a-z]+:\.` occurrence, so this change is likely safe for us.
>>
>> I think I'm looking at the same lists, and I see plenty of `.*` in the 
>> sanitizer exclusion lists. Also a few cases of `(abc|def|...)`. IIUC, those 
>> would both be broken by this -- instead of `.*` meaning "any character any 
>> number of times" (regex) it would mean "dot followed by any number of 
>> characters" (glob), right? And the `(abc|...)` would just be that literal 
>> text, not matching the individual parts?
>
> Sorry that my regex use was incorrect. We do have some `src:x/a.pb.*` style 
> rules, which are technically misused. `src:x/a.pb.*` can match possibly 
> unintended files like `x/axpbx`.
> To match just glob `x/a.pb.*` files, the rule should be written as 
> `src:x/a\.pb\.*` (`*` instead of `.*`), but I doubt anyone writes rules using 
> `\.`.
>
>> If my understanding of that is correct, I don't think this is a good change 
>> -- there's possibly plenty of configs out there that assume this is regex, 
>> and there doesn't seem to be sufficient motivation to just break those. But 
>> I can see that globs are useful for the examples posted in the patch 
>> description. Is it possible to have some middle ground, e.g. default to 
>> regex but allow a config at the top of sanitizer lists to interpret future 
>> patterns as globs instead?
>
> I think the main breakages are:
>
> - patterns using `(` and `)`. Our users don't have such patterns.
> - patterns using `\.` to mean a literal `.`, e.g. `src:a\.c`. Our users don't 
> use `\`. Such a pattern needs to changed to `src:a.c` (which used to match 
> other files like `axc`)
> - patterns like `src:a.pb.*` that match other files like `src:axpbx.c`. This 
> pattern can be changed to glob `src:a?pb?*`.
>
> I think all of these are likely uncommon. While `\.` is technically the 
> correct way to match a literal `.` before this patch, most people likely just 
> use `.`.
>
> In summary I think this patch is moving toward the right direction and making 
> the patterns less error-prone.

Actually, the code 

 will escape any character after `\`, not just special characters, so that 
`a\\` will match `a\`, `a\.` will match `a.`, and `a\a` will match `aa` (I'll 
have to make sure there are test cases for this). You are right that `.` is no 
longer a special character, which I believe is a major improvement.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154014/new/

https://reviews.llvm.org/D154014

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


[PATCH] D151589: [lld] add context-sensitive PGO options for MachO

2023-05-26 Thread Ellis Hoag via Phabricator via cfe-commits
ellis created this revision.
Herald added subscribers: wlei, ormris, wenlei, steven_wu, hiraditya.
Herald added projects: lld-macho, All.
Herald added a reviewer: lld-macho.
ellis added reviewers: int3, tejohnson, xur.
ellis updated this revision to Diff 526199.
ellis added a comment.
ellis edited the summary of this revision.
ellis edited the summary of this revision.
ellis edited the summary of this revision.
ellis published this revision for review.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

Only pass flags when using lld


Enable support for CSPGO for lld MachO targets.

Since lld MachO does not support `-plugin-opt=`, we need to create the 
`--cs-profile-generate` and `--cs-profile-path=` options and propagate them in 
`Darwin.cpp`. These flags are not supported by ld64.

Also outline code into `getLastCSProfileGenerateArg()` to share between 
`CommonArgs.cpp` and `Darwin.cpp`.

CSPGO is already implemented for ELF (https://reviews.llvm.org/D56675) and COFF 
(https://reviews.llvm.org/D98763).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151589

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/cspgo-lto.c
  lld/MachO/Config.h
  lld/MachO/Driver.cpp
  lld/MachO/LTO.cpp
  lld/MachO/Options.td

Index: lld/MachO/Options.td
===
--- lld/MachO/Options.td
+++ lld/MachO/Options.td
@@ -124,6 +124,10 @@
 def check_category_conflicts : Flag<["--"], "check-category-conflicts">,
 HelpText<"Check for conflicts between category & class methods">,
 Group;
+def cs_profile_generate: Flag<["--"], "cs-profile-generate">,
+HelpText<"Perform context senstive PGO instrumentation">, Group;
+def cs_profile_path: Joined<["--"], "cs-profile-path=">,
+HelpText<"Context sensitive profile file path">, Group;
 
 // This is a complete Options.td compiled from Apple's ld(1) manpage
 // dated 2018-03-07 and cross checked with ld64 source code in repo
Index: lld/MachO/LTO.cpp
===
--- lld/MachO/LTO.cpp
+++ lld/MachO/LTO.cpp
@@ -68,6 +68,8 @@
 
   c.TimeTraceEnabled = config->timeTraceEnabled;
   c.TimeTraceGranularity = config->timeTraceGranularity;
+  c.CSIRProfile = std::string(config->csProfilePath);
+  c.RunCSIRInstr = config->csProfileGenerate;
   c.OptLevel = config->ltoo;
   c.CGOptLevel = config->ltoCgo;
   if (config->saveTemps)
Index: lld/MachO/Driver.cpp
===
--- lld/MachO/Driver.cpp
+++ lld/MachO/Driver.cpp
@@ -1637,6 +1637,8 @@
   for (const Arg *arg : args.filtered(OPT_ignore_auto_link_option))
 config->ignoreAutoLinkOptions.insert(arg->getValue());
   config->strictAutoLink = args.hasArg(OPT_strict_auto_link);
+  config->csProfileGenerate = args.hasArg(OPT_cs_profile_generate);
+  config->csProfilePath = args.getLastArgValue(OPT_cs_profile_path);
 
   for (const Arg *arg : args.filtered(OPT_alias)) {
 config->aliasedSymbols.push_back(
Index: lld/MachO/Config.h
===
--- lld/MachO/Config.h
+++ lld/MachO/Config.h
@@ -206,6 +206,8 @@
   // so use a vector instead of a map.
   std::vector sectionAlignments;
   std::vector segmentProtections;
+  bool csProfileGenerate = false;
+  llvm::StringRef csProfilePath;
 
   bool callGraphProfileSort = false;
   llvm::StringRef printSymbolOrder;
Index: clang/test/Driver/cspgo-lto.c
===
--- clang/test/Driver/cspgo-lto.c
+++ clang/test/Driver/cspgo-lto.c
@@ -4,3 +4,17 @@
 // RUN:   -fprofile-use 2>&1 | FileCheck %s
 
 // CHECK: -plugin-opt=cs-profile-path=default.profdata
+
+// RUN: %clang -target apple-arm64-ios -### %t.o -flto=thin -fuse-ld=lld -fprofile-use 2>&1 | FileCheck %s --check-prefix=DARWIN-USE1
+// RUN: %clang -target apple-arm64-ios -### %t.o -flto=thin -fuse-ld=lld -fprofile-use=a.profdata 2>&1 | FileCheck %s --check-prefix=DARWIN-USE2
+
+// DARWIN-USE1: "--cs-profile-path=default.profdata"
+// DARWIN-USE2: "--cs-profile-path=a.profdata"
+
+// RUN: %clang -target apple-arm64-ios -### %t.o -flto=thin -fuse-ld=lld -fcs-profile-generate 2>&1 | FileCheck %s --check-prefix=DARWIN-GEN1
+// RUN: %clang -target apple-arm64-ios -### %t.o -flto=thin -fuse-ld=lld -fcs-profile-generate=/dump/here 2>&1 | FileCheck %s --check-prefix=DARWIN-GEN2
+
+// DARWIN-GEN1: "--cs-profile-generate"
+// DARWIN-GEN1-SAME: "--cs-profile-path=default_%m.profraw"
+// DARWIN-GEN2: "--cs-profile-generate"
+// DARWIN-GEN2-SAME: "--cs-profile-path=/dump/here/default_%m.profraw"
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -449,6 +449,23 @@
   Args.AddAllArgs(

[PATCH] D151589: [lld] add context-sensitive PGO options for MachO

2023-05-30 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 526751.
ellis marked 3 inline comments as done.
ellis added a comment.

Add test to check that `PGOInstrumentationGen`(`Use`) are run


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151589/new/

https://reviews.llvm.org/D151589

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/cspgo-lto.c
  lld/MachO/Config.h
  lld/MachO/Driver.cpp
  lld/MachO/LTO.cpp
  lld/MachO/Options.td
  lld/test/MachO/cspgo-gen.ll
  lld/test/MachO/cspgo-use.ll
  lld/test/lit.cfg.py

Index: lld/test/lit.cfg.py
===
--- lld/test/lit.cfg.py
+++ lld/test/lit.cfg.py
@@ -45,6 +45,7 @@
 "llvm-objdump",
 "llvm-otool",
 "llvm-pdbutil",
+"llvm-profdata",
 "llvm-dwarfdump",
 "llvm-readelf",
 "llvm-readobj",
Index: lld/test/MachO/cspgo-use.ll
===
--- /dev/null
+++ lld/test/MachO/cspgo-use.ll
@@ -0,0 +1,18 @@
+; REQUIRES: x86
+
+; Create an empty profile
+; RUN: echo > %t.proftext
+; RUN: llvm-profdata merge %t.proftext -o %t.profdata
+
+; RUN: llvm-as %s -o %t.o
+; RUN: %lld -dylib --cs-profile-path=%t.profdata %t.o -o %t --lto-debug-pass-manager 2>&1 | FileCheck %s --implicit-check-not=PGOInstrumentation
+
+; CHECK: Running pass: PGOInstrumentationUse
+
+target triple = "x86_64-apple-darwin"
+target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+
+define void @_start() {
+entry:
+  ret void
+}
Index: lld/test/MachO/cspgo-gen.ll
===
--- /dev/null
+++ lld/test/MachO/cspgo-gen.ll
@@ -0,0 +1,16 @@
+; REQUIRES: x86
+
+; RUN: llvm-as %s -o %t.o
+; RUN: %lld -dylib --cs-profile-generate --cs-profile-path=default_%m.profraw %t.o -o %t --lto-debug-pass-manager 2>&1 | FileCheck %s --implicit-check-not=PGOInstrumentation
+
+; CHECK: PGOInstrumentationGen
+
+target triple = "x86_64-apple-darwin"
+target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+
+@__llvm_profile_runtime = global i32 0, align 4
+
+define void @_start() {
+entry:
+  ret void
+}
Index: lld/MachO/Options.td
===
--- lld/MachO/Options.td
+++ lld/MachO/Options.td
@@ -126,6 +126,10 @@
 Group;
 def lto_debug_pass_manager: Flag<["--"], "lto-debug-pass-manager">,
 HelpText<"Debug new pass manager">, Group;
+def cs_profile_generate: Flag<["--"], "cs-profile-generate">,
+HelpText<"Perform context senstive PGO instrumentation">, Group;
+def cs_profile_path: Joined<["--"], "cs-profile-path=">,
+HelpText<"Context sensitive profile file path">, Group;
 
 // This is a complete Options.td compiled from Apple's ld(1) manpage
 // dated 2018-03-07 and cross checked with ld64 source code in repo
Index: lld/MachO/LTO.cpp
===
--- lld/MachO/LTO.cpp
+++ lld/MachO/LTO.cpp
@@ -69,6 +69,8 @@
   c.TimeTraceEnabled = config->timeTraceEnabled;
   c.TimeTraceGranularity = config->timeTraceGranularity;
   c.DebugPassManager = config->ltoDebugPassManager;
+  c.CSIRProfile = std::string(config->csProfilePath);
+  c.RunCSIRInstr = config->csProfileGenerate;
   c.OptLevel = config->ltoo;
   c.CGOptLevel = config->ltoCgo;
   if (config->saveTemps)
Index: lld/MachO/Driver.cpp
===
--- lld/MachO/Driver.cpp
+++ lld/MachO/Driver.cpp
@@ -1638,6 +1638,8 @@
 config->ignoreAutoLinkOptions.insert(arg->getValue());
   config->strictAutoLink = args.hasArg(OPT_strict_auto_link);
   config->ltoDebugPassManager = args.hasArg(OPT_lto_debug_pass_manager);
+  config->csProfileGenerate = args.hasArg(OPT_cs_profile_generate);
+  config->csProfilePath = args.getLastArgValue(OPT_cs_profile_path);
 
   for (const Arg *arg : args.filtered(OPT_alias)) {
 config->aliasedSymbols.push_back(
Index: lld/MachO/Config.h
===
--- lld/MachO/Config.h
+++ lld/MachO/Config.h
@@ -207,6 +207,8 @@
   std::vector sectionAlignments;
   std::vector segmentProtections;
   bool ltoDebugPassManager = false;
+  bool csProfileGenerate = false;
+  llvm::StringRef csProfilePath;
 
   bool callGraphProfileSort = false;
   llvm::StringRef printSymbolOrder;
Index: clang/test/Driver/cspgo-lto.c
===
--- clang/test/Driver/cspgo-lto.c
+++ clang/test/Driver/cspgo-lto.c
@@ -4,3 +4,17 @@
 // RUN:   -fprofile-use 2>&1 | FileCheck %s
 
 // CHECK: -plugin-opt=cs-profile-path=default.profdata
+
+// RUN: %clang --target=apple-arm64-ios -### %t.o -flto=thin -fuse-ld=lld -fprofile-use 2>&1 | FileCheck %s --check-prefix=DARWIN-USE1
+//

[PATCH] D151589: [lld] add context-sensitive PGO options for MachO

2023-05-30 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 526825.
ellis marked 3 inline comments as not done.
ellis added a comment.

Rename test function to `foo` since `_start` is not a necessary symbol


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151589/new/

https://reviews.llvm.org/D151589

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/cspgo-lto.c
  lld/MachO/Config.h
  lld/MachO/Driver.cpp
  lld/MachO/LTO.cpp
  lld/MachO/Options.td
  lld/test/MachO/cspgo-gen.ll
  lld/test/MachO/cspgo-use.ll
  lld/test/lit.cfg.py

Index: lld/test/lit.cfg.py
===
--- lld/test/lit.cfg.py
+++ lld/test/lit.cfg.py
@@ -45,6 +45,7 @@
 "llvm-objdump",
 "llvm-otool",
 "llvm-pdbutil",
+"llvm-profdata",
 "llvm-dwarfdump",
 "llvm-readelf",
 "llvm-readobj",
Index: lld/test/MachO/cspgo-use.ll
===
--- /dev/null
+++ lld/test/MachO/cspgo-use.ll
@@ -0,0 +1,18 @@
+; REQUIRES: x86
+
+; Create an empty profile
+; RUN: echo > %t.proftext
+; RUN: llvm-profdata merge %t.proftext -o %t.profdata
+
+; RUN: llvm-as %s -o %t.o
+; RUN: %lld -dylib --cs-profile-path=%t.profdata %t.o -o %t --lto-debug-pass-manager 2>&1 | FileCheck %s --implicit-check-not=PGOInstrumentation
+
+; CHECK: Running pass: PGOInstrumentationUse
+
+target triple = "x86_64-apple-darwin"
+target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+
+define void @foo() {
+entry:
+  ret void
+}
Index: lld/test/MachO/cspgo-gen.ll
===
--- /dev/null
+++ lld/test/MachO/cspgo-gen.ll
@@ -0,0 +1,16 @@
+; REQUIRES: x86
+
+; RUN: llvm-as %s -o %t.o
+; RUN: %lld -dylib --cs-profile-generate --cs-profile-path=default_%m.profraw %t.o -o %t --lto-debug-pass-manager 2>&1 | FileCheck %s --implicit-check-not=PGOInstrumentation
+
+; CHECK: PGOInstrumentationGen
+
+target triple = "x86_64-apple-darwin"
+target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+
+@__llvm_profile_runtime = global i32 0, align 4
+
+define void @foo() {
+entry:
+  ret void
+}
Index: lld/MachO/Options.td
===
--- lld/MachO/Options.td
+++ lld/MachO/Options.td
@@ -126,6 +126,10 @@
 Group;
 def lto_debug_pass_manager: Flag<["--"], "lto-debug-pass-manager">,
 HelpText<"Debug new pass manager">, Group;
+def cs_profile_generate: Flag<["--"], "cs-profile-generate">,
+HelpText<"Perform context senstive PGO instrumentation">, Group;
+def cs_profile_path: Joined<["--"], "cs-profile-path=">,
+HelpText<"Context sensitive profile file path">, Group;
 
 // This is a complete Options.td compiled from Apple's ld(1) manpage
 // dated 2018-03-07 and cross checked with ld64 source code in repo
Index: lld/MachO/LTO.cpp
===
--- lld/MachO/LTO.cpp
+++ lld/MachO/LTO.cpp
@@ -69,6 +69,8 @@
   c.TimeTraceEnabled = config->timeTraceEnabled;
   c.TimeTraceGranularity = config->timeTraceGranularity;
   c.DebugPassManager = config->ltoDebugPassManager;
+  c.CSIRProfile = std::string(config->csProfilePath);
+  c.RunCSIRInstr = config->csProfileGenerate;
   c.OptLevel = config->ltoo;
   c.CGOptLevel = config->ltoCgo;
   if (config->saveTemps)
Index: lld/MachO/Driver.cpp
===
--- lld/MachO/Driver.cpp
+++ lld/MachO/Driver.cpp
@@ -1638,6 +1638,8 @@
 config->ignoreAutoLinkOptions.insert(arg->getValue());
   config->strictAutoLink = args.hasArg(OPT_strict_auto_link);
   config->ltoDebugPassManager = args.hasArg(OPT_lto_debug_pass_manager);
+  config->csProfileGenerate = args.hasArg(OPT_cs_profile_generate);
+  config->csProfilePath = args.getLastArgValue(OPT_cs_profile_path);
 
   for (const Arg *arg : args.filtered(OPT_alias)) {
 config->aliasedSymbols.push_back(
Index: lld/MachO/Config.h
===
--- lld/MachO/Config.h
+++ lld/MachO/Config.h
@@ -207,6 +207,8 @@
   std::vector sectionAlignments;
   std::vector segmentProtections;
   bool ltoDebugPassManager = false;
+  bool csProfileGenerate = false;
+  llvm::StringRef csProfilePath;
 
   bool callGraphProfileSort = false;
   llvm::StringRef printSymbolOrder;
Index: clang/test/Driver/cspgo-lto.c
===
--- clang/test/Driver/cspgo-lto.c
+++ clang/test/Driver/cspgo-lto.c
@@ -4,3 +4,17 @@
 // RUN:   -fprofile-use 2>&1 | FileCheck %s
 
 // CHECK: -plugin-opt=cs-profile-path=default.profdata
+
+// RUN: %clang --target=apple-arm64-ios -### %t.o -flto=thin -fuse-ld=lld -fprofile-use 2>&1 | FileCheck %s --check-prefix=DARWIN-U

[PATCH] D151589: [lld] add context-sensitive PGO options for MachO

2023-05-31 Thread Ellis Hoag via Phabricator via cfe-commits
ellis updated this revision to Diff 527205.
ellis added a comment.

Fix paths in clang test to support windows


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151589/new/

https://reviews.llvm.org/D151589

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/cspgo-lto.c
  lld/MachO/Config.h
  lld/MachO/Driver.cpp
  lld/MachO/LTO.cpp
  lld/MachO/Options.td
  lld/test/MachO/cspgo-gen.ll
  lld/test/MachO/cspgo-use.ll
  lld/test/lit.cfg.py

Index: lld/test/lit.cfg.py
===
--- lld/test/lit.cfg.py
+++ lld/test/lit.cfg.py
@@ -45,6 +45,7 @@
 "llvm-objdump",
 "llvm-otool",
 "llvm-pdbutil",
+"llvm-profdata",
 "llvm-dwarfdump",
 "llvm-readelf",
 "llvm-readobj",
Index: lld/test/MachO/cspgo-use.ll
===
--- /dev/null
+++ lld/test/MachO/cspgo-use.ll
@@ -0,0 +1,18 @@
+; REQUIRES: x86
+
+; Create an empty profile
+; RUN: echo > %t.proftext
+; RUN: llvm-profdata merge %t.proftext -o %t.profdata
+
+; RUN: llvm-as %s -o %t.o
+; RUN: %lld -dylib --cs-profile-path=%t.profdata %t.o -o %t --lto-debug-pass-manager 2>&1 | FileCheck %s --implicit-check-not=PGOInstrumentation
+
+; CHECK: Running pass: PGOInstrumentationUse
+
+target triple = "x86_64-apple-darwin"
+target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+
+define void @foo() {
+entry:
+  ret void
+}
Index: lld/test/MachO/cspgo-gen.ll
===
--- /dev/null
+++ lld/test/MachO/cspgo-gen.ll
@@ -0,0 +1,16 @@
+; REQUIRES: x86
+
+; RUN: llvm-as %s -o %t.o
+; RUN: %lld -dylib --cs-profile-generate --cs-profile-path=default_%m.profraw %t.o -o %t --lto-debug-pass-manager 2>&1 | FileCheck %s --implicit-check-not=PGOInstrumentation
+
+; CHECK: PGOInstrumentationGen
+
+target triple = "x86_64-apple-darwin"
+target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+
+@__llvm_profile_runtime = global i32 0, align 4
+
+define void @foo() {
+entry:
+  ret void
+}
Index: lld/MachO/Options.td
===
--- lld/MachO/Options.td
+++ lld/MachO/Options.td
@@ -126,6 +126,10 @@
 Group;
 def lto_debug_pass_manager: Flag<["--"], "lto-debug-pass-manager">,
 HelpText<"Debug new pass manager">, Group;
+def cs_profile_generate: Flag<["--"], "cs-profile-generate">,
+HelpText<"Perform context senstive PGO instrumentation">, Group;
+def cs_profile_path: Joined<["--"], "cs-profile-path=">,
+HelpText<"Context sensitive profile file path">, Group;
 
 // This is a complete Options.td compiled from Apple's ld(1) manpage
 // dated 2018-03-07 and cross checked with ld64 source code in repo
Index: lld/MachO/LTO.cpp
===
--- lld/MachO/LTO.cpp
+++ lld/MachO/LTO.cpp
@@ -69,6 +69,8 @@
   c.TimeTraceEnabled = config->timeTraceEnabled;
   c.TimeTraceGranularity = config->timeTraceGranularity;
   c.DebugPassManager = config->ltoDebugPassManager;
+  c.CSIRProfile = std::string(config->csProfilePath);
+  c.RunCSIRInstr = config->csProfileGenerate;
   c.OptLevel = config->ltoo;
   c.CGOptLevel = config->ltoCgo;
   if (config->saveTemps)
Index: lld/MachO/Driver.cpp
===
--- lld/MachO/Driver.cpp
+++ lld/MachO/Driver.cpp
@@ -1637,6 +1637,8 @@
 config->ignoreAutoLinkOptions.insert(arg->getValue());
   config->strictAutoLink = args.hasArg(OPT_strict_auto_link);
   config->ltoDebugPassManager = args.hasArg(OPT_lto_debug_pass_manager);
+  config->csProfileGenerate = args.hasArg(OPT_cs_profile_generate);
+  config->csProfilePath = args.getLastArgValue(OPT_cs_profile_path);
 
   for (const Arg *arg : args.filtered(OPT_alias)) {
 config->aliasedSymbols.push_back(
Index: lld/MachO/Config.h
===
--- lld/MachO/Config.h
+++ lld/MachO/Config.h
@@ -206,6 +206,8 @@
   std::vector sectionAlignments;
   std::vector segmentProtections;
   bool ltoDebugPassManager = false;
+  bool csProfileGenerate = false;
+  llvm::StringRef csProfilePath;
 
   bool callGraphProfileSort = false;
   llvm::StringRef printSymbolOrder;
Index: clang/test/Driver/cspgo-lto.c
===
--- clang/test/Driver/cspgo-lto.c
+++ clang/test/Driver/cspgo-lto.c
@@ -4,3 +4,17 @@
 // RUN:   -fprofile-use 2>&1 | FileCheck %s
 
 // CHECK: -plugin-opt=cs-profile-path=default.profdata
+
+// RUN: %clang --target=apple-arm64-ios -### %t.o -flto=thin -fuse-ld=lld -fprofile-use 2>&1 | FileCheck %s --check-prefix=DARWIN-USE1
+// RUN: %clang --target=apple-arm64-ios -### %t.o -flto=thin -fuse-

[PATCH] D151589: [lld] add context-sensitive PGO options for MachO

2023-05-31 Thread Ellis Hoag via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG85af42df5dbb: [lld] add context-sensitive PGO options for 
MachO (authored by ellis).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151589/new/

https://reviews.llvm.org/D151589

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/cspgo-lto.c
  lld/MachO/Config.h
  lld/MachO/Driver.cpp
  lld/MachO/LTO.cpp
  lld/MachO/Options.td
  lld/test/MachO/cspgo-gen.ll
  lld/test/MachO/cspgo-use.ll
  lld/test/lit.cfg.py

Index: lld/test/lit.cfg.py
===
--- lld/test/lit.cfg.py
+++ lld/test/lit.cfg.py
@@ -45,6 +45,7 @@
 "llvm-objdump",
 "llvm-otool",
 "llvm-pdbutil",
+"llvm-profdata",
 "llvm-dwarfdump",
 "llvm-readelf",
 "llvm-readobj",
Index: lld/test/MachO/cspgo-use.ll
===
--- /dev/null
+++ lld/test/MachO/cspgo-use.ll
@@ -0,0 +1,18 @@
+; REQUIRES: x86
+
+; Create an empty profile
+; RUN: echo > %t.proftext
+; RUN: llvm-profdata merge %t.proftext -o %t.profdata
+
+; RUN: llvm-as %s -o %t.o
+; RUN: %lld -dylib --cs-profile-path=%t.profdata %t.o -o %t --lto-debug-pass-manager 2>&1 | FileCheck %s --implicit-check-not=PGOInstrumentation
+
+; CHECK: Running pass: PGOInstrumentationUse
+
+target triple = "x86_64-apple-darwin"
+target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+
+define void @foo() {
+entry:
+  ret void
+}
Index: lld/test/MachO/cspgo-gen.ll
===
--- /dev/null
+++ lld/test/MachO/cspgo-gen.ll
@@ -0,0 +1,16 @@
+; REQUIRES: x86
+
+; RUN: llvm-as %s -o %t.o
+; RUN: %lld -dylib --cs-profile-generate --cs-profile-path=default_%m.profraw %t.o -o %t --lto-debug-pass-manager 2>&1 | FileCheck %s --implicit-check-not=PGOInstrumentation
+
+; CHECK: PGOInstrumentationGen
+
+target triple = "x86_64-apple-darwin"
+target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+
+@__llvm_profile_runtime = global i32 0, align 4
+
+define void @foo() {
+entry:
+  ret void
+}
Index: lld/MachO/Options.td
===
--- lld/MachO/Options.td
+++ lld/MachO/Options.td
@@ -126,6 +126,10 @@
 Group;
 def lto_debug_pass_manager: Flag<["--"], "lto-debug-pass-manager">,
 HelpText<"Debug new pass manager">, Group;
+def cs_profile_generate: Flag<["--"], "cs-profile-generate">,
+HelpText<"Perform context senstive PGO instrumentation">, Group;
+def cs_profile_path: Joined<["--"], "cs-profile-path=">,
+HelpText<"Context sensitive profile file path">, Group;
 
 // This is a complete Options.td compiled from Apple's ld(1) manpage
 // dated 2018-03-07 and cross checked with ld64 source code in repo
Index: lld/MachO/LTO.cpp
===
--- lld/MachO/LTO.cpp
+++ lld/MachO/LTO.cpp
@@ -69,6 +69,8 @@
   c.TimeTraceEnabled = config->timeTraceEnabled;
   c.TimeTraceGranularity = config->timeTraceGranularity;
   c.DebugPassManager = config->ltoDebugPassManager;
+  c.CSIRProfile = std::string(config->csProfilePath);
+  c.RunCSIRInstr = config->csProfileGenerate;
   c.OptLevel = config->ltoo;
   c.CGOptLevel = config->ltoCgo;
   if (config->saveTemps)
Index: lld/MachO/Driver.cpp
===
--- lld/MachO/Driver.cpp
+++ lld/MachO/Driver.cpp
@@ -1637,6 +1637,8 @@
 config->ignoreAutoLinkOptions.insert(arg->getValue());
   config->strictAutoLink = args.hasArg(OPT_strict_auto_link);
   config->ltoDebugPassManager = args.hasArg(OPT_lto_debug_pass_manager);
+  config->csProfileGenerate = args.hasArg(OPT_cs_profile_generate);
+  config->csProfilePath = args.getLastArgValue(OPT_cs_profile_path);
 
   for (const Arg *arg : args.filtered(OPT_alias)) {
 config->aliasedSymbols.push_back(
Index: lld/MachO/Config.h
===
--- lld/MachO/Config.h
+++ lld/MachO/Config.h
@@ -206,6 +206,8 @@
   std::vector sectionAlignments;
   std::vector segmentProtections;
   bool ltoDebugPassManager = false;
+  bool csProfileGenerate = false;
+  llvm::StringRef csProfilePath;
 
   bool callGraphProfileSort = false;
   llvm::StringRef printSymbolOrder;
Index: clang/test/Driver/cspgo-lto.c
===
--- clang/test/Driver/cspgo-lto.c
+++ clang/test/Driver/cspgo-lto.c
@@ -4,3 +4,17 @@
 // RUN:   -fprofile-use 2>&1 | FileCheck %s
 
 // CHECK: -plugin-opt=cs-profile-path=default.profdata
+
+// RUN: %clang --target=apple-arm64-ios -### %t.o -flto=thin -fuse-ld=lld -fprof

[PATCH] D152762: [clang][docs] Update SanitizerSpecialCaseList docs

2023-06-12 Thread Ellis Hoag via Phabricator via cfe-commits
ellis created this revision.
Herald added a project: All.
ellis retitled this revision from "[clang][docs] Update Sanitizer docs and 
test" to "[clang][docs] Update SanitizerSpecialCaseList docs".
ellis edited the summary of this revision.
ellis added reviewers: vlad.tsyrklevich, MaskRay.
ellis published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The docs in `SanitizerSpecialCaseList.rst` seem to be outdated.

- "The meaning of * in regular expression for entity names is different - it is 
treated as in shell wildcarding."
  - This is wrong because `*/foo.c` will match `/path/to/foo.c` instead of just 
`something/foo.c`. Instead, `*` is treated as `.*` and filepaths are treated as 
strings.
- I've removed `fun:MyFooBar` since it made it seem like we could match 
demangled names.

To confirm these changes, I've extended the `profile-filter-new.c` test and 
updated it to use `split-file`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152762

Files:
  clang/docs/SanitizerSpecialCaseList.rst
  clang/test/CodeGen/profile-filter-new.c

Index: clang/test/CodeGen/profile-filter-new.c
===
--- clang/test/CodeGen/profile-filter-new.c
+++ clang/test/CodeGen/profile-filter-new.c
@@ -1,20 +1,14 @@
-// RUN: %clang_cc1 -fprofile-instrument=llvm -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}"
+// RUN: split-file %s %t
 
-// RUN: echo -e "[llvm]\nfunction:foo=skip" > %t0.list
-// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t0.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}" --check-prefixes=CHECK,SKIP-FOO
-
-// RUN: echo -e "[csllvm]\nfunction:bar=forbid" > %t1.list
-// RUN: %clang_cc1 -fprofile-instrument=csllvm -fprofile-list=%t1.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}" --check-prefixes=CHECK,FORBID-BAR
-// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t1.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}"
-
-// RUN: echo -e "[llvm]\ndefault:forbid\nfunction:foo=allow" > %t2.list
-// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t2.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}" --check-prefixes=CHECK,FORBID
-
-// RUN: echo "[llvm]" > %t2.list
-// RUN: echo "source:%s=forbid" | sed -e 's/\\//g' >> %t2.list
-// RUN: echo "function:foo=allow" >> %t2.list
-// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t2.list -emit-llvm %s -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}" --check-prefixes=CHECK,FORBID
+// RUN: %clang_cc1 -fprofile-instrument=llvm -emit-llvm %t/Inputs/src/code.c -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}"
+// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t/Inputs/skip-foo.txt -emit-llvm %t/Inputs/src/code.c -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}" --check-prefixes=CHECK,SKIP-FOO
+// RUN: %clang_cc1 -fprofile-instrument=csllvm -fprofile-list=%t/Inputs/forbid-bar.txt -emit-llvm %t/Inputs/src/code.c -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}" --check-prefixes=CHECK,FORBID-BAR
+// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t/Inputs/forbid-bar.txt -emit-llvm %t/Inputs/src/code.c -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}"
+// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t/Inputs/forbid-default.txt -emit-llvm %t/Inputs/src/code.c -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}" --check-prefixes=CHECK,FORBID
+// RUN: %clang_cc1 -fprofile-instrument=csllvm -fprofile-list=%t/Inputs/forbid-default.txt -emit-llvm %t/Inputs/src/code.c -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}" --check-prefixes=CHECK,FORBID
+// RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t/Inputs/forbid-source.txt -emit-llvm %t/Inputs/src/code.c -o - | FileCheck %s --implicit-check-not="; {{.* (noprofile|skipprofile)}}" --check-prefixes=CHECK,FORBID
 
+//--- Inputs/src/code.c
 // SKIP-FOO: skipprofile
 // CHECK-LABEL: define {{.*}} @foo
 int foo(int a) { return 4 * a + 1; }
@@ -27,3 +21,26 @@
 // FORBID: noprofile
 // CHECK-LABEL: define {{.*}} @goo
 int goo(int a) { return 4 * a + 3; }
+
+//--- Inputs/skip-foo.txt
+[llvm]
+# This is a comment
+# Use mangled names to select functions
+function:foo=skip
+
+//--- Inputs/forbid-bar.txt
+[csllvm]
+function:bar=forbid
+
+//--- Inputs/forbid-default.txt
+[llvm|csllvm]
+default:forbid
+function:foo=allow
+
+//--- Inputs/forbid-source.txt
+[llvm]
+# The "*" prefix matches the whole directory "%t/Inputs/" and "(/|\\)" matches
+# unix-like and windows path separators
+source:*(/|\\)src(/|\\)code.c=forbid
+# Function entries take

[PATCH] D152762: [clang][docs] Update SanitizerSpecialCaseList docs

2023-06-14 Thread Ellis Hoag via Phabricator via cfe-commits
ellis planned changes to this revision.
ellis added a comment.

In D152762#4421630 , @phosek wrote:

> This is unrelated to this change but related to the issue this change is 
> addressing. The use of regular expressions for special case list with the 
> special handling of `*` is error-prone, I've seen many people having issues 
> it. Furthermore, regular expression for matching file names requires 
> excessive escaping (see for example 
> https://fuchsia-review.git.corp.google.com/c/fuchsia/+/763162) and most 
> patterns used for function names only utilize `*`, not requiring the full 
> strength of regular expression. I think we should consider replacing regular 
> expressions with glob patterns. These are already implemented in 
> https://github.com/llvm/llvm-project/blob/3391bdc255f1a75c59d71c7305959e84d8d5f468/llvm/include/llvm/Support/GlobPattern.h
>  so the implementation should be straightforward, but it's going to be a 
> breaking change. I don't know how widespread the use of special case lists is 
> and whether that's going to be an issue?

Oh neat, I wasn't aware of `GlobPattern.h`. Personally, I would be happy with 
this change, but it would require changing some blocklists on my end (which is 
fine). I'm not sure what the processes is for a breaking change like this, but 
since clang 16 has just been released, it seems like a good time to change 
this. Thoughts?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152762/new/

https://reviews.llvm.org/D152762

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


  1   2   >