[clang] [llvm] [Pipelines] Do not run CoroSplit and CoroCleanup in LTO pre-link pipeline (PR #100205)

2024-07-29 Thread Wei Wang via cfe-commits

https://github.com/apolloww updated 
https://github.com/llvm/llvm-project/pull/100205

>From 041670dc6a8e9f6a86af152567f0705034db6ad2 Mon Sep 17 00:00:00 2001
From: Wei Wang 
Date: Mon, 29 Apr 2024 10:24:53 -0700
Subject: [PATCH 1/2] [Pipelines] Do not run CoroSplit and CoroCleanup in
 ThinLTO pre-link pipeline

Skip CoroSplit and CoroCleanup in ThinLTO pre-link pipeline so that
CoroElide can happen after callee coroutine is imported into caller's
module in ThinLTO.
---
 .../CodeGenCoroutines/coro-elide-thinlto.cpp  | 84 +++
 llvm/lib/Passes/PassBuilderPipelines.cpp  | 11 ++-
 .../Other/new-pm-thinlto-prelink-defaults.ll  |  2 -
 .../new-pm-thinlto-prelink-pgo-defaults.ll|  2 -
 ...w-pm-thinlto-prelink-samplepgo-defaults.ll |  2 -
 5 files changed, 91 insertions(+), 10 deletions(-)
 create mode 100644 clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp

diff --git a/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp 
b/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
new file mode 100644
index 0..16bee64df9a11
--- /dev/null
+++ b/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
@@ -0,0 +1,84 @@
+// REQUIRES: x86_64-linux
+// This tests that the coroutine elide optimization could happen succesfully 
with ThinLTO.
+// This test is adapted from coro-elide.cpp and splits functions into two 
files.
+//
+// RUN: split-file %s %t
+// RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin -I %S -c 
%t/coro-elide-callee.cpp -o coro-elide-callee.bc
+// RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin -I %S -c 
%t/coro-elide-caller.cpp -o coro-elide-caller.bc
+// RUN: llvm-lto --thinlto coro-elide-callee.bc coro-elide-caller.bc -o summary
+// RUN: %clang_cc1 -O2 -x ir coro-elide-caller.bc 
-fthinlto-index=summary.thinlto.bc -emit-llvm -o - | FileCheck %s
+//
+// Run asan
+// RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin 
-fsanitize=address -I %S -c %t/coro-elide-callee.cpp -o coro-elide-callee.bc
+// RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin 
-fsanitize=address -I %S -c %t/coro-elide-caller.cpp -o coro-elide-caller.bc
+// RUN: llvm-lto --thinlto coro-elide-callee.bc coro-elide-caller.bc -o summary
+// RUN: %clang_cc1 -O2 -x ir coro-elide-caller.bc 
-fthinlto-index=summary.thinlto.bc -emit-llvm -o - | FileCheck %s
+
+//--- coro-elide-task.h
+#pragma once
+#include "Inputs/coroutine.h"
+
+struct Task {
+  struct promise_type {
+struct FinalAwaiter {
+  bool await_ready() const noexcept { return false; }
+  template 
+  std::coroutine_handle<> await_suspend(std::coroutine_handle 
h) noexcept {
+if (!h)
+  return std::noop_coroutine();
+return h.promise().continuation;
+  }
+  void await_resume() noexcept {}
+};
+Task get_return_object() noexcept {
+  return std::coroutine_handle::from_promise(*this);
+}
+std::suspend_always initial_suspend() noexcept { return {}; }
+FinalAwaiter final_suspend() noexcept { return {}; }
+void unhandled_exception() noexcept {}
+void return_value(int x) noexcept {
+  _value = x;
+}
+std::coroutine_handle<> continuation;
+int _value;
+  };
+
+  Task(std::coroutine_handle handle) : handle(handle) {}
+  ~Task() {
+if (handle)
+  handle.destroy();
+  }
+
+  struct Awaiter {
+bool await_ready() const noexcept { return false; }
+void await_suspend(std::coroutine_handle continuation) noexcept {}
+int await_resume() noexcept {
+  return 43;
+}
+  };
+
+  auto operator co_await() {
+return Awaiter{};
+  }
+
+private:
+  std::coroutine_handle handle;
+};
+
+//--- coro-elide-callee.cpp
+#include "coro-elide-task.h"
+Task task0() {
+  co_return 43;
+}
+
+//--- coro-elide-caller.cpp
+#include "coro-elide-task.h"
+
+Task task0();
+
+Task task1() {
+  co_return co_await task0();
+}
+
+// CHECK-LABEL: define{{.*}} void @_Z5task1v.resume
+// CHECK-NOT: {{.*}}_Znwm
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp 
b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 757b20dcd6693..a6118726945e8 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -979,7 +979,8 @@ PassBuilder::buildInlinerPipeline(OptimizationLevel Level,
   MainCGPipeline.addPass(createCGSCCToFunctionPassAdaptor(
   RequireAnalysisPass()));
 
-  MainCGPipeline.addPass(CoroSplitPass(Level != OptimizationLevel::O0));
+  if (Phase != ThinOrFullLTOPhase::ThinLTOPreLink)
+MainCGPipeline.addPass(CoroSplitPass(Level != OptimizationLevel::O0));
 
   // Make sure we don't affect potential future NoRerun CGSCC adaptors.
   MIWP.addLateModulePass(createModuleToFunctionPassAdaptor(
@@ -1021,8 +1022,9 @@ PassBuilder::buildModuleInlinerPipeline(OptimizationLevel 
Level,
   buildFunctionSimplificationPipeline(Level, Phase),
   PTO.EagerlyInvalidateAnalyses));
 
-  MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(
-  CoroSplitPass(Level != OptimizationLevel::O0)));
+ 

[clang] [llvm] [Pipelines] Do not run CoroSplit and CoroCleanup in LTO pre-link pipeline (PR #100205)

2024-07-29 Thread Wei Wang via cfe-commits

https://github.com/apolloww updated 
https://github.com/llvm/llvm-project/pull/100205

>From bd652d600a1b1c71fcc2d399f33024ca5c78f5ce Mon Sep 17 00:00:00 2001
From: Wei Wang 
Date: Mon, 29 Apr 2024 10:24:53 -0700
Subject: [PATCH] [Pipelines] Do not run CoroSplit and CoroCleanup in ThinLTO
 pre-link pipeline

Skip CoroSplit and CoroCleanup in ThinLTO pre-link pipeline so that
CoroElide can happen after callee coroutine is imported into caller's
module in ThinLTO.
---
 .../CodeGenCoroutines/coro-elide-thinlto.cpp  | 84 +++
 llvm/lib/Passes/PassBuilderPipelines.cpp  | 11 ++-
 .../Other/new-pm-thinlto-prelink-defaults.ll  |  2 -
 .../new-pm-thinlto-prelink-pgo-defaults.ll|  2 -
 ...w-pm-thinlto-prelink-samplepgo-defaults.ll |  2 -
 5 files changed, 91 insertions(+), 10 deletions(-)
 create mode 100644 clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp

diff --git a/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp 
b/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
new file mode 100644
index 0..16bee64df9a11
--- /dev/null
+++ b/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
@@ -0,0 +1,84 @@
+// REQUIRES: x86_64-linux
+// This tests that the coroutine elide optimization could happen succesfully 
with ThinLTO.
+// This test is adapted from coro-elide.cpp and splits functions into two 
files.
+//
+// RUN: split-file %s %t
+// RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin -I %S -c 
%t/coro-elide-callee.cpp -o coro-elide-callee.bc
+// RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin -I %S -c 
%t/coro-elide-caller.cpp -o coro-elide-caller.bc
+// RUN: llvm-lto --thinlto coro-elide-callee.bc coro-elide-caller.bc -o summary
+// RUN: %clang_cc1 -O2 -x ir coro-elide-caller.bc 
-fthinlto-index=summary.thinlto.bc -emit-llvm -o - | FileCheck %s
+//
+// Run asan
+// RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin 
-fsanitize=address -I %S -c %t/coro-elide-callee.cpp -o coro-elide-callee.bc
+// RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin 
-fsanitize=address -I %S -c %t/coro-elide-caller.cpp -o coro-elide-caller.bc
+// RUN: llvm-lto --thinlto coro-elide-callee.bc coro-elide-caller.bc -o summary
+// RUN: %clang_cc1 -O2 -x ir coro-elide-caller.bc 
-fthinlto-index=summary.thinlto.bc -emit-llvm -o - | FileCheck %s
+
+//--- coro-elide-task.h
+#pragma once
+#include "Inputs/coroutine.h"
+
+struct Task {
+  struct promise_type {
+struct FinalAwaiter {
+  bool await_ready() const noexcept { return false; }
+  template 
+  std::coroutine_handle<> await_suspend(std::coroutine_handle 
h) noexcept {
+if (!h)
+  return std::noop_coroutine();
+return h.promise().continuation;
+  }
+  void await_resume() noexcept {}
+};
+Task get_return_object() noexcept {
+  return std::coroutine_handle::from_promise(*this);
+}
+std::suspend_always initial_suspend() noexcept { return {}; }
+FinalAwaiter final_suspend() noexcept { return {}; }
+void unhandled_exception() noexcept {}
+void return_value(int x) noexcept {
+  _value = x;
+}
+std::coroutine_handle<> continuation;
+int _value;
+  };
+
+  Task(std::coroutine_handle handle) : handle(handle) {}
+  ~Task() {
+if (handle)
+  handle.destroy();
+  }
+
+  struct Awaiter {
+bool await_ready() const noexcept { return false; }
+void await_suspend(std::coroutine_handle continuation) noexcept {}
+int await_resume() noexcept {
+  return 43;
+}
+  };
+
+  auto operator co_await() {
+return Awaiter{};
+  }
+
+private:
+  std::coroutine_handle handle;
+};
+
+//--- coro-elide-callee.cpp
+#include "coro-elide-task.h"
+Task task0() {
+  co_return 43;
+}
+
+//--- coro-elide-caller.cpp
+#include "coro-elide-task.h"
+
+Task task0();
+
+Task task1() {
+  co_return co_await task0();
+}
+
+// CHECK-LABEL: define{{.*}} void @_Z5task1v.resume
+// CHECK-NOT: {{.*}}_Znwm
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp 
b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 935504b070d2e..62084912687d8 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -978,7 +978,8 @@ PassBuilder::buildInlinerPipeline(OptimizationLevel Level,
   MainCGPipeline.addPass(createCGSCCToFunctionPassAdaptor(
   RequireAnalysisPass()));
 
-  MainCGPipeline.addPass(CoroSplitPass(Level != OptimizationLevel::O0));
+  if (Phase != ThinOrFullLTOPhase::ThinLTOPreLink)
+MainCGPipeline.addPass(CoroSplitPass(Level != OptimizationLevel::O0));
 
   // Make sure we don't affect potential future NoRerun CGSCC adaptors.
   MIWP.addLateModulePass(createModuleToFunctionPassAdaptor(
@@ -1020,8 +1021,9 @@ PassBuilder::buildModuleInlinerPipeline(OptimizationLevel 
Level,
   buildFunctionSimplificationPipeline(Level, Phase),
   PTO.EagerlyInvalidateAnalyses));
 
-  MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(
-  CoroSplitPass(Level != OptimizationLevel::O0)));
+  if 

[clang] [llvm] [Pipelines] Do not run CoroSplit and CoroCleanup in LTO pre-link pipeline (PR #100205)

2024-07-23 Thread Wei Wang via cfe-commits

apolloww wrote:

@vitalybuka I am landing the pipeline change again. Please let me know if you 
see issues again later. 

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


[clang] [llvm] [Pipelines] Do not run CoroSplit and CoroCleanup in LTO pre-link pipeline (PR #100205)

2024-07-23 Thread Wei Wang via cfe-commits

https://github.com/apolloww created 
https://github.com/llvm/llvm-project/pull/100205

This is re-land of #90310 after making asan skip pre-split coroutines in #99415.

Skip CoroSplit and CoroCleanup in LTO pre-link pipeline so that CoroElide can 
happen after callee coroutine is imported into caller's module in ThinLTO.

>From bd652d600a1b1c71fcc2d399f33024ca5c78f5ce Mon Sep 17 00:00:00 2001
From: Wei Wang 
Date: Mon, 29 Apr 2024 10:24:53 -0700
Subject: [PATCH] [Pipelines] Do not run CoroSplit and CoroCleanup in ThinLTO
 pre-link pipeline

Skip CoroSplit and CoroCleanup in ThinLTO pre-link pipeline so that
CoroElide can happen after callee coroutine is imported into caller's
module in ThinLTO.
---
 .../CodeGenCoroutines/coro-elide-thinlto.cpp  | 84 +++
 llvm/lib/Passes/PassBuilderPipelines.cpp  | 11 ++-
 .../Other/new-pm-thinlto-prelink-defaults.ll  |  2 -
 .../new-pm-thinlto-prelink-pgo-defaults.ll|  2 -
 ...w-pm-thinlto-prelink-samplepgo-defaults.ll |  2 -
 5 files changed, 91 insertions(+), 10 deletions(-)
 create mode 100644 clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp

diff --git a/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp 
b/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
new file mode 100644
index 0..16bee64df9a11
--- /dev/null
+++ b/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
@@ -0,0 +1,84 @@
+// REQUIRES: x86_64-linux
+// This tests that the coroutine elide optimization could happen succesfully 
with ThinLTO.
+// This test is adapted from coro-elide.cpp and splits functions into two 
files.
+//
+// RUN: split-file %s %t
+// RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin -I %S -c 
%t/coro-elide-callee.cpp -o coro-elide-callee.bc
+// RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin -I %S -c 
%t/coro-elide-caller.cpp -o coro-elide-caller.bc
+// RUN: llvm-lto --thinlto coro-elide-callee.bc coro-elide-caller.bc -o summary
+// RUN: %clang_cc1 -O2 -x ir coro-elide-caller.bc 
-fthinlto-index=summary.thinlto.bc -emit-llvm -o - | FileCheck %s
+//
+// Run asan
+// RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin 
-fsanitize=address -I %S -c %t/coro-elide-callee.cpp -o coro-elide-callee.bc
+// RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin 
-fsanitize=address -I %S -c %t/coro-elide-caller.cpp -o coro-elide-caller.bc
+// RUN: llvm-lto --thinlto coro-elide-callee.bc coro-elide-caller.bc -o summary
+// RUN: %clang_cc1 -O2 -x ir coro-elide-caller.bc 
-fthinlto-index=summary.thinlto.bc -emit-llvm -o - | FileCheck %s
+
+//--- coro-elide-task.h
+#pragma once
+#include "Inputs/coroutine.h"
+
+struct Task {
+  struct promise_type {
+struct FinalAwaiter {
+  bool await_ready() const noexcept { return false; }
+  template 
+  std::coroutine_handle<> await_suspend(std::coroutine_handle 
h) noexcept {
+if (!h)
+  return std::noop_coroutine();
+return h.promise().continuation;
+  }
+  void await_resume() noexcept {}
+};
+Task get_return_object() noexcept {
+  return std::coroutine_handle::from_promise(*this);
+}
+std::suspend_always initial_suspend() noexcept { return {}; }
+FinalAwaiter final_suspend() noexcept { return {}; }
+void unhandled_exception() noexcept {}
+void return_value(int x) noexcept {
+  _value = x;
+}
+std::coroutine_handle<> continuation;
+int _value;
+  };
+
+  Task(std::coroutine_handle handle) : handle(handle) {}
+  ~Task() {
+if (handle)
+  handle.destroy();
+  }
+
+  struct Awaiter {
+bool await_ready() const noexcept { return false; }
+void await_suspend(std::coroutine_handle continuation) noexcept {}
+int await_resume() noexcept {
+  return 43;
+}
+  };
+
+  auto operator co_await() {
+return Awaiter{};
+  }
+
+private:
+  std::coroutine_handle handle;
+};
+
+//--- coro-elide-callee.cpp
+#include "coro-elide-task.h"
+Task task0() {
+  co_return 43;
+}
+
+//--- coro-elide-caller.cpp
+#include "coro-elide-task.h"
+
+Task task0();
+
+Task task1() {
+  co_return co_await task0();
+}
+
+// CHECK-LABEL: define{{.*}} void @_Z5task1v.resume
+// CHECK-NOT: {{.*}}_Znwm
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp 
b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 935504b070d2e..62084912687d8 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -978,7 +978,8 @@ PassBuilder::buildInlinerPipeline(OptimizationLevel Level,
   MainCGPipeline.addPass(createCGSCCToFunctionPassAdaptor(
   RequireAnalysisPass()));
 
-  MainCGPipeline.addPass(CoroSplitPass(Level != OptimizationLevel::O0));
+  if (Phase != ThinOrFullLTOPhase::ThinLTOPreLink)
+MainCGPipeline.addPass(CoroSplitPass(Level != OptimizationLevel::O0));
 
   // Make sure we don't affect potential future NoRerun CGSCC adaptors.
   MIWP.addLateModulePass(createModuleToFunctionPassAdaptor(
@@ -1020,8 +1021,9 @@ 

[clang] [clang][NFC] fix name lookup for llvm::json::Value in SymbolGraphSerializer (PR #94511)

2024-06-06 Thread Wei Wang via cfe-commits

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

LGTM.

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


[clang] [llvm] [Pipelines] Do not run CoroSplit and CoroCleanup in LTO pre-link pipeline (PR #90310)

2024-04-30 Thread Wei Wang via cfe-commits


@@ -0,0 +1,77 @@
+// This tests that the coroutine elide optimization could happen succesfully 
with ThinLTO.
+// This test is adapted from coro-elide.cpp and splits functions into two 
files.
+//
+// RUN: split-file %s %t
+// RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin -I %S -c 
%t/coro-elide-callee.cpp -o coro-elide-callee.o
+// RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin -I %S -c 
%t/coro-elide-caller.cpp -o coro-elide-caller.o

apolloww wrote:

Just landed #90672 to limit the test to x86 linux targets. Did that fix the 
test failure?

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


[clang] [Coroutines][Test] Only run coro-elide-thinlto under x86_64-linux (PR #90672)

2024-04-30 Thread Wei Wang via cfe-commits

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


[clang] [Coroutines][Test] Only run coro-elide-thinlto under x86_64-linux (PR #90672)

2024-04-30 Thread Wei Wang via cfe-commits

apolloww wrote:

> This test has been failing on bots for several hours now. Can we either get 
> this fix in or the original change reverted to get the bots back to green? 
> One failing bot is https://lab.llvm.org/buildbot/#/builders/280/builds/2876.

sorry for the breakage, the same fix is included in #90690. Will land shortly.

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


[clang] [llvm] [Pipelines][Coroutines] Tune coroutine passes only for ThinLTO pre-link pipeline (PR #90690)

2024-04-30 Thread Wei Wang via cfe-commits

https://github.com/apolloww created 
https://github.com/llvm/llvm-project/pull/90690

Follow up to #90310, limit the tune up only to ThinLTO pre-link as coroutine 
passes are not in MonoLTO backend

Also coro-elide-thinlto test is still failing on some Buildbots, only run the 
test under x86_64 linux target. 

>From a47f8207a73f850acbc493f827a127c6aa52db77 Mon Sep 17 00:00:00 2001
From: Wei Wang 
Date: Tue, 30 Apr 2024 16:48:24 -0700
Subject: [PATCH] fix coro mono lto

---
 clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp | 1 +
 llvm/lib/Passes/PassBuilderPipelines.cpp| 6 +++---
 llvm/test/Other/new-pm-defaults.ll  | 6 ++
 3 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp 
b/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
index d0e60e67963dfd..5b2d0146578437 100644
--- a/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
+++ b/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
@@ -1,3 +1,4 @@
+// REQUIRES: x86_64-linux
 // This tests that the coroutine elide optimization could happen succesfully 
with ThinLTO.
 // This test is adapted from coro-elide.cpp and splits functions into two 
files.
 //
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp 
b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 594549034cc829..100889c0845bc3 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -963,7 +963,7 @@ PassBuilder::buildInlinerPipeline(OptimizationLevel Level,
   MainCGPipeline.addPass(createCGSCCToFunctionPassAdaptor(
   RequireAnalysisPass()));
 
-  if (!isLTOPreLink(Phase))
+  if (Phase != ThinOrFullLTOPhase::ThinLTOPreLink)
 MainCGPipeline.addPass(CoroSplitPass(Level != OptimizationLevel::O0));
 
   // Make sure we don't affect potential future NoRerun CGSCC adaptors.
@@ -1006,7 +1006,7 @@ PassBuilder::buildModuleInlinerPipeline(OptimizationLevel 
Level,
   buildFunctionSimplificationPipeline(Level, Phase),
   PTO.EagerlyInvalidateAnalyses));
 
-  if (!isLTOPreLink(Phase))
+  if (Phase != ThinOrFullLTOPhase::ThinLTOPreLink)
 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(
 CoroSplitPass(Level != OptimizationLevel::O0)));
 
@@ -1185,7 +1185,7 @@ 
PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
   // and argument promotion.
   MPM.addPass(DeadArgumentEliminationPass());
 
-  if (!isLTOPreLink(Phase))
+  if (Phase != ThinOrFullLTOPhase::ThinLTOPreLink)
 MPM.addPass(CoroCleanupPass());
 
   // Optimize globals now that functions are fully simplified.
diff --git a/llvm/test/Other/new-pm-defaults.ll 
b/llvm/test/Other/new-pm-defaults.ll
index ebfed7b687e2ce..51fb93daa4dfa6 100644
--- a/llvm/test/Other/new-pm-defaults.ll
+++ b/llvm/test/Other/new-pm-defaults.ll
@@ -224,14 +224,12 @@
 ; CHECK-O-NEXT: Running pass: PostOrderFunctionAttrsPass
 ; CHECK-O-NEXT: Running pass: 
RequireAnalysisPass<{{.*}}ShouldNotRunFunctionPassesAnalysis
 ; CHECK-O-NEXT: Running analysis: ShouldNotRunFunctionPassesAnalysis
-; CHECK-DEFAULT-NEXT: Running pass: CoroSplitPass
-; CHECK-LTO-NOT: Running pass: CoroSplitPass
+; CHECK-O-NEXT: Running pass: CoroSplitPass
 ; CHECK-O-NEXT: Running pass: 
InvalidateAnalysisPass<{{.*}}ShouldNotRunFunctionPassesAnalysis
 ; CHECK-O-NEXT: Invalidating analysis: ShouldNotRunFunctionPassesAnalysis
 ; CHECK-O-NEXT: Invalidating analysis: InlineAdvisorAnalysis
 ; CHECK-O-NEXT: Running pass: DeadArgumentEliminationPass
-; CHECK-DEFAULT-NEXT: Running pass: CoroCleanupPass
-; CHECK-LTO-NOT: Running pass: CoroCleanupPass
+; CHECK-O-NEXT: Running pass: CoroCleanupPass
 ; CHECK-O-NEXT: Running pass: GlobalOptPass
 ; CHECK-O-NEXT: Running pass: GlobalDCEPass
 ; CHECK-DEFAULT-NEXT: Running pass: EliminateAvailableExternallyPass

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


[clang] [llvm] [Pipelines] Do not run CoroSplit and CoroCleanup in LTO pre-link pipeline (PR #90310)

2024-04-30 Thread Wei Wang via cfe-commits

apolloww wrote:

OK, so Mono LTO backend pipeline does not have any coro passes. We can add 
coroutine passes to `buildLTODefaultPipeline`, but I am not sure how big the 
use case it is. For now, I'll limit the tuning to ThinLTO only. Will send an 
update soon.

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


[clang] [llvm] [Pipelines] Do not run CoroSplit and CoroCleanup in LTO pre-link pipeline (PR #90310)

2024-04-30 Thread Wei Wang via cfe-commits

apolloww wrote:

hmm, this looks like `llvm.coro.subfn.addr` is not lowered before codegen 
starts. And this is for wasm and MonoLTO. Let me check.

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


[clang] [Coroutines][Test] Only run coro-elide-thinlto under x86_64-linux (PR #90672)

2024-04-30 Thread Wei Wang via cfe-commits

apolloww wrote:

https://lab.llvm.org/buildbot/#/builders/188/builds/45187

```
Error running ThinLTO backend: No available targets are compatible with triple 
"x86_64-unknown-linux"
```


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


[clang] [Coroutines][Test] Only run coro-elide-thinlto under x86_64-linux (PR #90672)

2024-04-30 Thread Wei Wang via cfe-commits

https://github.com/apolloww created 
https://github.com/llvm/llvm-project/pull/90672

Previous fix #90549 didn't completely address the Buildbot failures. Some 
target may not recognize the target triple. This time, only run the test under 
x86_64-linux.

>From 66d63598d0c29cc7232715d0abfcfcc640dc97c8 Mon Sep 17 00:00:00 2001
From: Wei Wang 
Date: Tue, 30 Apr 2024 14:50:36 -0700
Subject: [PATCH] fix build failure

---
 clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp 
b/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
index d0e60e67963dfd..5b2d0146578437 100644
--- a/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
+++ b/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
@@ -1,3 +1,4 @@
+// REQUIRES: x86_64-linux
 // This tests that the coroutine elide optimization could happen succesfully 
with ThinLTO.
 // This test is adapted from coro-elide.cpp and splits functions into two 
files.
 //

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


[clang] [Coroutines][Test] Specify target triple in coro-elide-thinlto (PR #90549)

2024-04-30 Thread Wei Wang via cfe-commits

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


[clang] [Coroutines][Test] Specify target triple in coro-elide-thinlto (PR #90549)

2024-04-30 Thread Wei Wang via cfe-commits

https://github.com/apolloww updated 
https://github.com/llvm/llvm-project/pull/90549

>From 1fac46855bf6bb3feb2e8b7a0918e61c8468ea07 Mon Sep 17 00:00:00 2001
From: Wei Wang 
Date: Mon, 29 Apr 2024 20:01:29 -0700
Subject: [PATCH] fix build failure

---
 clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp 
b/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
index 790899486ec9d1..57d0a7f037d536 100644
--- a/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
+++ b/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
@@ -5,7 +5,7 @@
 // RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin -I %S -c 
%t/coro-elide-callee.cpp -o %t/coro-elide-callee.o
 // RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin -I %S -c 
%t/coro-elide-caller.cpp -o %t/coro-elide-caller.o
 // RUN: llvm-lto -thinlto %t/coro-elide-callee.o %t/coro-elide-caller.o -o 
summary
-// RUN: %clang_cc1 -O2 -x ir %t/coro-elide-caller.o 
-fthinlto-index=summary.thinlto.bc -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -O2 -x ir 
%t/coro-elide-caller.o -fthinlto-index=summary.thinlto.bc -emit-llvm -o - | 
FileCheck %s
 
 //--- coro-elide-task.h
 #pragma once

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


[clang] [Coroutines][Test] Specify target triple in coro-elide-thinlto (PR #90549)

2024-04-29 Thread Wei Wang via cfe-commits

https://github.com/apolloww updated 
https://github.com/llvm/llvm-project/pull/90549

>From 1fac46855bf6bb3feb2e8b7a0918e61c8468ea07 Mon Sep 17 00:00:00 2001
From: Wei Wang 
Date: Mon, 29 Apr 2024 20:01:29 -0700
Subject: [PATCH] fix build failure

---
 clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp 
b/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
index 790899486ec9d1..57d0a7f037d536 100644
--- a/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
+++ b/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
@@ -5,7 +5,7 @@
 // RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin -I %S -c 
%t/coro-elide-callee.cpp -o %t/coro-elide-callee.o
 // RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin -I %S -c 
%t/coro-elide-caller.cpp -o %t/coro-elide-caller.o
 // RUN: llvm-lto -thinlto %t/coro-elide-callee.o %t/coro-elide-caller.o -o 
summary
-// RUN: %clang_cc1 -O2 -x ir %t/coro-elide-caller.o 
-fthinlto-index=summary.thinlto.bc -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -O2 -x ir 
%t/coro-elide-caller.o -fthinlto-index=summary.thinlto.bc -emit-llvm -o - | 
FileCheck %s
 
 //--- coro-elide-task.h
 #pragma once

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


[clang] [Coroutines][Test] Specify target triple in coro-elide-thinlto (PR #90549)

2024-04-29 Thread Wei Wang via cfe-commits

apolloww wrote:

This should make Buildbot failure like 
https://lab.llvm.org/buildbot/#/builders/38/builds/19079 to go away

```
warning: linking module 'coro-elide-caller.o': Linking two modules of different 
target triples: 'coro-elide-callee.o' is 'x86_64-unknown-linux' whereas 
'coro-elide-caller.o' is 'hexagon-unknown-unknown-elf'
```

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


[clang] [Coroutines][Test] Specify target triple in coro-elide-thinlto (PR #90549)

2024-04-29 Thread Wei Wang via cfe-commits

https://github.com/apolloww created 
https://github.com/llvm/llvm-project/pull/90549

Resolve test failure on non-x86 linux host

>From 4cdba5174c49682502e65d6f10224bb2bc54f346 Mon Sep 17 00:00:00 2001
From: Wei Wang 
Date: Mon, 29 Apr 2024 20:01:29 -0700
Subject: [PATCH] fix build failure

---
 clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp 
b/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
index 293aef6781677f..50e8648a09d450 100644
--- a/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
+++ b/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
@@ -5,7 +5,7 @@
 // RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin -I %S -c 
%t/coro-elide-callee.cpp -o coro-elide-callee.o
 // RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin -I %S -c 
%t/coro-elide-caller.cpp -o coro-elide-caller.o
 // RUN: llvm-lto -thinlto coro-elide-callee.o coro-elide-caller.o -o summary
-// RUN: %clang_cc1 -O2 -x ir coro-elide-caller.o 
-fthinlto-index=summary.thinlto.bc -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -O2 -x ir coro-elide-caller.o 
-fthinlto-index=summary.thinlto.bc -emit-llvm -o - | FileCheck %s
 
 //--- coro-elide-task.h
 #pragma once

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


[clang] [llvm] [Pipelines] Do not run CoroSplit and CoroCleanup in LTO pre-link pipeline (PR #90310)

2024-04-29 Thread Wei Wang via cfe-commits

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


[clang] [llvm] [Pipelines] Do not run CoroSplit and CoroCleanup in LTO pre-link pipeline (PR #90310)

2024-04-26 Thread Wei Wang via cfe-commits

https://github.com/apolloww updated 
https://github.com/llvm/llvm-project/pull/90310

>From c0ba0d5b49fec06d0ca23214acc1ccef43013c01 Mon Sep 17 00:00:00 2001
From: Wei Wang 
Date: Fri, 26 Apr 2024 14:47:31 -0700
Subject: [PATCH 1/2] update pipeline

---
 .../CodeGenCoroutines/coro-elide-thinlto.cpp  | 77 +++
 llvm/lib/Passes/PassBuilderPipelines.cpp  | 12 ++-
 llvm/test/Other/new-pm-defaults.ll|  6 +-
 .../Other/new-pm-thinlto-prelink-defaults.ll  |  2 -
 .../new-pm-thinlto-prelink-pgo-defaults.ll|  2 -
 ...w-pm-thinlto-prelink-samplepgo-defaults.ll |  2 -
 6 files changed, 89 insertions(+), 12 deletions(-)
 create mode 100644 clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp

diff --git a/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp 
b/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
new file mode 100644
index 00..293aef6781677f
--- /dev/null
+++ b/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
@@ -0,0 +1,77 @@
+// This tests that the coroutine elide optimization could happen succesfully 
with ThinLTO.
+// This test is adapted from coro-elide.cpp and splits functions into two 
files.
+//
+// RUN: split-file %s %t
+// RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin -I %S -c 
%t/coro-elide-callee.cpp -o coro-elide-callee.o
+// RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin -I %S -c 
%t/coro-elide-caller.cpp -o coro-elide-caller.o
+// RUN: llvm-lto -thinlto coro-elide-callee.o coro-elide-caller.o -o summary
+// RUN: %clang_cc1 -O2 -x ir coro-elide-caller.o 
-fthinlto-index=summary.thinlto.bc -emit-llvm -o - | FileCheck %s
+
+//--- coro-elide-task.h
+#pragma once
+#include "Inputs/coroutine.h"
+
+struct Task {
+  struct promise_type {
+struct FinalAwaiter {
+  bool await_ready() const noexcept { return false; }
+  template 
+  std::coroutine_handle<> await_suspend(std::coroutine_handle 
h) noexcept {
+if (!h)
+  return std::noop_coroutine();
+return h.promise().continuation;
+  }
+  void await_resume() noexcept {}
+};
+Task get_return_object() noexcept {
+  return std::coroutine_handle::from_promise(*this);
+}
+std::suspend_always initial_suspend() noexcept { return {}; }
+FinalAwaiter final_suspend() noexcept { return {}; }
+void unhandled_exception() noexcept {}
+void return_value(int x) noexcept {
+  _value = x;
+}
+std::coroutine_handle<> continuation;
+int _value;
+  };
+
+  Task(std::coroutine_handle handle) : handle(handle) {}
+  ~Task() {
+if (handle)
+  handle.destroy();
+  }
+
+  struct Awaiter {
+bool await_ready() const noexcept { return false; }
+void await_suspend(std::coroutine_handle continuation) noexcept {}
+int await_resume() noexcept {
+  return 43;
+}
+  };
+
+  auto operator co_await() {
+return Awaiter{};
+  }
+
+private:
+  std::coroutine_handle handle;
+};
+
+//--- coro-elide-callee.cpp
+#include "coro-elide-task.h"
+Task task0() {
+  co_return 43;
+}
+
+//--- coro-elide-caller.cpp
+#include "coro-elide-task.h"
+
+Task task0();
+
+Task task1() {
+  co_return co_await task0();
+}
+
+// CHECK-LABEL: define{{.*}} void @_Z5task1v.resume
+// CHECK-NOT: {{.*}}_Znwm
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp 
b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 90ba3b541553e2..4ca8aff479b0ff 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -963,7 +963,8 @@ PassBuilder::buildInlinerPipeline(OptimizationLevel Level,
   MainCGPipeline.addPass(createCGSCCToFunctionPassAdaptor(
   RequireAnalysisPass()));
 
-  MainCGPipeline.addPass(CoroSplitPass(Level != OptimizationLevel::O0));
+  if (!isLTOPreLink(Phase))
+MainCGPipeline.addPass(CoroSplitPass(Level != OptimizationLevel::O0));
 
   // Make sure we don't affect potential future NoRerun CGSCC adaptors.
   MIWP.addLateModulePass(createModuleToFunctionPassAdaptor(
@@ -1005,8 +1006,10 @@ 
PassBuilder::buildModuleInlinerPipeline(OptimizationLevel Level,
   buildFunctionSimplificationPipeline(Level, Phase),
   PTO.EagerlyInvalidateAnalyses));
 
-  MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(
-  CoroSplitPass(Level != OptimizationLevel::O0)));
+
+  if (!isLTOPreLink(Phase))
+MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(
+CoroSplitPass(Level != OptimizationLevel::O0)));
 
   return MPM;
 }
@@ -1183,7 +1186,8 @@ 
PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
   // and argument promotion.
   MPM.addPass(DeadArgumentEliminationPass());
 
-  MPM.addPass(CoroCleanupPass());
+  if (!isLTOPreLink(Phase))
+MPM.addPass(CoroCleanupPass());
 
   // Optimize globals now that functions are fully simplified.
   MPM.addPass(GlobalOptPass());
diff --git a/llvm/test/Other/new-pm-defaults.ll 
b/llvm/test/Other/new-pm-defaults.ll
index 51fb93daa4dfa6..ebfed7b687e2ce 100644
--- a/llvm/test/Other/new-pm-defaults.ll
+++ 

[clang] [llvm] [Pipelines] Do not run CoroSplit and CoroCleanup in LTO pre-link pipeline (PR #90310)

2024-04-26 Thread Wei Wang via cfe-commits

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


[clang] [llvm] [Pipelines] Do not run CoroSplit and CoroCleanup in LTO pre-link pipeline (PR #90310)

2024-04-26 Thread Wei Wang via cfe-commits

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


[clang] [llvm] [Pipelines] Do not run CoroSplit and CoroCleanup in pre-lto pipeline (PR #90310)

2024-04-26 Thread Wei Wang via cfe-commits

https://github.com/apolloww created 
https://github.com/llvm/llvm-project/pull/90310

Skip CoroSplit and CoroCleanup in pre-lto pipeline so that CoroElide can happen 
after callee coroutine is imported into caller's module in ThinLTO.

>From c0ba0d5b49fec06d0ca23214acc1ccef43013c01 Mon Sep 17 00:00:00 2001
From: Wei Wang 
Date: Fri, 26 Apr 2024 14:47:31 -0700
Subject: [PATCH] update pipeline

---
 .../CodeGenCoroutines/coro-elide-thinlto.cpp  | 77 +++
 llvm/lib/Passes/PassBuilderPipelines.cpp  | 12 ++-
 llvm/test/Other/new-pm-defaults.ll|  6 +-
 .../Other/new-pm-thinlto-prelink-defaults.ll  |  2 -
 .../new-pm-thinlto-prelink-pgo-defaults.ll|  2 -
 ...w-pm-thinlto-prelink-samplepgo-defaults.ll |  2 -
 6 files changed, 89 insertions(+), 12 deletions(-)
 create mode 100644 clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp

diff --git a/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp 
b/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
new file mode 100644
index 00..293aef6781677f
--- /dev/null
+++ b/clang/test/CodeGenCoroutines/coro-elide-thinlto.cpp
@@ -0,0 +1,77 @@
+// This tests that the coroutine elide optimization could happen succesfully 
with ThinLTO.
+// This test is adapted from coro-elide.cpp and splits functions into two 
files.
+//
+// RUN: split-file %s %t
+// RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin -I %S -c 
%t/coro-elide-callee.cpp -o coro-elide-callee.o
+// RUN: %clang --target=x86_64-linux -std=c++20 -O2 -flto=thin -I %S -c 
%t/coro-elide-caller.cpp -o coro-elide-caller.o
+// RUN: llvm-lto -thinlto coro-elide-callee.o coro-elide-caller.o -o summary
+// RUN: %clang_cc1 -O2 -x ir coro-elide-caller.o 
-fthinlto-index=summary.thinlto.bc -emit-llvm -o - | FileCheck %s
+
+//--- coro-elide-task.h
+#pragma once
+#include "Inputs/coroutine.h"
+
+struct Task {
+  struct promise_type {
+struct FinalAwaiter {
+  bool await_ready() const noexcept { return false; }
+  template 
+  std::coroutine_handle<> await_suspend(std::coroutine_handle 
h) noexcept {
+if (!h)
+  return std::noop_coroutine();
+return h.promise().continuation;
+  }
+  void await_resume() noexcept {}
+};
+Task get_return_object() noexcept {
+  return std::coroutine_handle::from_promise(*this);
+}
+std::suspend_always initial_suspend() noexcept { return {}; }
+FinalAwaiter final_suspend() noexcept { return {}; }
+void unhandled_exception() noexcept {}
+void return_value(int x) noexcept {
+  _value = x;
+}
+std::coroutine_handle<> continuation;
+int _value;
+  };
+
+  Task(std::coroutine_handle handle) : handle(handle) {}
+  ~Task() {
+if (handle)
+  handle.destroy();
+  }
+
+  struct Awaiter {
+bool await_ready() const noexcept { return false; }
+void await_suspend(std::coroutine_handle continuation) noexcept {}
+int await_resume() noexcept {
+  return 43;
+}
+  };
+
+  auto operator co_await() {
+return Awaiter{};
+  }
+
+private:
+  std::coroutine_handle handle;
+};
+
+//--- coro-elide-callee.cpp
+#include "coro-elide-task.h"
+Task task0() {
+  co_return 43;
+}
+
+//--- coro-elide-caller.cpp
+#include "coro-elide-task.h"
+
+Task task0();
+
+Task task1() {
+  co_return co_await task0();
+}
+
+// CHECK-LABEL: define{{.*}} void @_Z5task1v.resume
+// CHECK-NOT: {{.*}}_Znwm
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp 
b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 90ba3b541553e2..4ca8aff479b0ff 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -963,7 +963,8 @@ PassBuilder::buildInlinerPipeline(OptimizationLevel Level,
   MainCGPipeline.addPass(createCGSCCToFunctionPassAdaptor(
   RequireAnalysisPass()));
 
-  MainCGPipeline.addPass(CoroSplitPass(Level != OptimizationLevel::O0));
+  if (!isLTOPreLink(Phase))
+MainCGPipeline.addPass(CoroSplitPass(Level != OptimizationLevel::O0));
 
   // Make sure we don't affect potential future NoRerun CGSCC adaptors.
   MIWP.addLateModulePass(createModuleToFunctionPassAdaptor(
@@ -1005,8 +1006,10 @@ 
PassBuilder::buildModuleInlinerPipeline(OptimizationLevel Level,
   buildFunctionSimplificationPipeline(Level, Phase),
   PTO.EagerlyInvalidateAnalyses));
 
-  MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(
-  CoroSplitPass(Level != OptimizationLevel::O0)));
+
+  if (!isLTOPreLink(Phase))
+MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(
+CoroSplitPass(Level != OptimizationLevel::O0)));
 
   return MPM;
 }
@@ -1183,7 +1186,8 @@ 
PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
   // and argument promotion.
   MPM.addPass(DeadArgumentEliminationPass());
 
-  MPM.addPass(CoroCleanupPass());
+  if (!isLTOPreLink(Phase))
+MPM.addPass(CoroCleanupPass());
 
   // Optimize globals now that functions are fully simplified.
   MPM.addPass(GlobalOptPass());
diff --git 

[clang] [Clang][test] Limit library search when linking shared lib (PR #80253)

2024-02-01 Thread Wei Wang via cfe-commits

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


[clang] [Clang][test] Limit library search when linking shared lib (PR #80253)

2024-01-31 Thread Wei Wang via cfe-commits

apolloww wrote:

Our internal builds run in chroot and the test fails with the following error

```
/bin/ld: cannot find crti.o: No such file or directory
/bin/ld: cannot find crtbeginS.o: No such file or directory
/bin/ld: cannot find -lgcc
/bin/ld: cannot find -lgcc_s
/bin/ld: cannot find -lc
/bin/ld: cannot find -lgcc
/bin/ld: cannot find -lgcc_s
/bin/ld: cannot find crtendS.o: No such file or directory
/bin/ld: cannot find crtn.o: No such file or directory
```

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


[clang] [Clang][test] Limit library search when linking shared lib (PR #80253)

2024-01-31 Thread Wei Wang via cfe-commits

https://github.com/apolloww created 
https://github.com/llvm/llvm-project/pull/80253

Don't search for unnecessary libs when linking the shared lib. This allows the 
test to run in chroot environment.

>From adc0635a10fc4d77842863c4f9b731733c9b8062 Mon Sep 17 00:00:00 2001
From: Wei Wang 
Date: Wed, 31 Jan 2024 23:21:45 -0800
Subject: [PATCH] [Clang][test] Limit library search when linking shared lib

---
 clang/test/Interpreter/cxx20-modules.cppm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Interpreter/cxx20-modules.cppm 
b/clang/test/Interpreter/cxx20-modules.cppm
index 239968d8c7445..4e56e2fc1528a 100644
--- a/clang/test/Interpreter/cxx20-modules.cppm
+++ b/clang/test/Interpreter/cxx20-modules.cppm
@@ -8,7 +8,7 @@
 // RUN: %clang -std=c++20 %t/mod.cppm --precompile \
 // RUN: -o %t/mod.pcm --target=x86_64-linux-gnu
 // RUN: %clang -fPIC %t/mod.pcm -c -o %t/mod.o --target=x86_64-linux-gnu
-// RUN: %clang -fPIC -shared %t/mod.o -o %t/libmod.so --target=x86_64-linux-gnu
+// RUN: %clang -nostdlib -fPIC -shared %t/mod.o -o %t/libmod.so 
--target=x86_64-linux-gnu
 //
 // RUN: cat %t/import.cpp | env LD_LIBRARY_PATH=%t:$LD_LIBRARY_PATH \
 // RUN: clang-repl -Xcc=-std=c++20 -Xcc=-fmodule-file=M=%t/mod.pcm \

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


[clang] [clang] Make sure the same UsingType is searched and inserted (PR #79182)

2024-01-24 Thread Wei Wang via cfe-commits

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


[clang] [clang] Make sure the same UsingType is searched and inserted (PR #79182)

2024-01-23 Thread Wei Wang via cfe-commits

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


[clang] [clang] Make sure the same UsingType is searched and inserted (PR #79182)

2024-01-23 Thread Wei Wang via cfe-commits

apolloww wrote:

Thanks. Added test case.

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


[clang] [clang] Make sure the same UsingType is searched and inserted (PR #79182)

2024-01-23 Thread Wei Wang via cfe-commits

https://github.com/apolloww updated 
https://github.com/llvm/llvm-project/pull/79182

>From a542d63f472d799eb2d041c82cac402cfb8dec1a Mon Sep 17 00:00:00 2001
From: Wei Wang 
Date: Tue, 23 Jan 2024 10:01:57 -0800
Subject: [PATCH 1/3] [clang] Make sure the same UsingType is searched and
 inserted

---
 clang/lib/AST/ASTContext.cpp | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 5eb7aa3664569dd..d312ef61fb15d4a 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -4672,12 +4672,6 @@ QualType ASTContext::getTypedefType(const 
TypedefNameDecl *Decl,
 QualType ASTContext::getUsingType(const UsingShadowDecl *Found,
   QualType Underlying) const {
   llvm::FoldingSetNodeID ID;
-  UsingType::Profile(ID, Found, Underlying);
-
-  void *InsertPos = nullptr;
-  if (UsingType *T = UsingTypes.FindNodeOrInsertPos(ID, InsertPos))
-return QualType(T, 0);
-
   const Type *TypeForDecl =
   cast(Found->getTargetDecl())->getTypeForDecl();
 
@@ -4687,6 +4681,13 @@ QualType ASTContext::getUsingType(const UsingShadowDecl 
*Found,
 
   if (Underlying.getTypePtr() == TypeForDecl)
 Underlying = QualType();
+  UsingType::Profile(ID, Found, Underlying);
+
+  void *InsertPos = nullptr;
+  if (UsingType *T = UsingTypes.FindNodeOrInsertPos(ID, InsertPos)) {
+return QualType(T, 0);
+  }
+
   void *Mem =
   Allocate(UsingType::totalSizeToAlloc(!Underlying.isNull()),
alignof(UsingType));

>From 6dba099a2e1f06feb65248678a57bd00a3d4d0ae Mon Sep 17 00:00:00 2001
From: Wei Wang 
Date: Tue, 23 Jan 2024 19:58:24 -0800
Subject: [PATCH 2/3] update UsingType profile implementation

---
 clang/include/clang/AST/Type.h |  5 ++---
 clang/lib/AST/ASTContext.cpp   | 13 ++---
 2 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index ea425791fc97f05..3d411051084c71b 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -4729,13 +4729,12 @@ class UsingType final : public Type,
   bool typeMatchesDecl() const { return !UsingBits.hasTypeDifferentFromDecl; }
 
   void Profile(llvm::FoldingSetNodeID ) {
-Profile(ID, Found, typeMatchesDecl() ? QualType() : getUnderlyingType());
+Profile(ID, Found, getUnderlyingType());
   }
   static void Profile(llvm::FoldingSetNodeID , const UsingShadowDecl *Found,
   QualType Underlying) {
 ID.AddPointer(Found);
-if (!Underlying.isNull())
-  Underlying.Profile(ID);
+Underlying.Profile(ID);
   }
   static bool classof(const Type *T) { return T->getTypeClass() == Using; }
 };
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index d312ef61fb15d4a..5eb7aa3664569dd 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -4672,6 +4672,12 @@ QualType ASTContext::getTypedefType(const 
TypedefNameDecl *Decl,
 QualType ASTContext::getUsingType(const UsingShadowDecl *Found,
   QualType Underlying) const {
   llvm::FoldingSetNodeID ID;
+  UsingType::Profile(ID, Found, Underlying);
+
+  void *InsertPos = nullptr;
+  if (UsingType *T = UsingTypes.FindNodeOrInsertPos(ID, InsertPos))
+return QualType(T, 0);
+
   const Type *TypeForDecl =
   cast(Found->getTargetDecl())->getTypeForDecl();
 
@@ -4681,13 +4687,6 @@ QualType ASTContext::getUsingType(const UsingShadowDecl 
*Found,
 
   if (Underlying.getTypePtr() == TypeForDecl)
 Underlying = QualType();
-  UsingType::Profile(ID, Found, Underlying);
-
-  void *InsertPos = nullptr;
-  if (UsingType *T = UsingTypes.FindNodeOrInsertPos(ID, InsertPos)) {
-return QualType(T, 0);
-  }
-
   void *Mem =
   Allocate(UsingType::totalSizeToAlloc(!Underlying.isNull()),
alignof(UsingType));

>From 4c1fc38bd8d7967afa2c557c4f8ec2a6019779d4 Mon Sep 17 00:00:00 2001
From: Wei Wang 
Date: Tue, 23 Jan 2024 23:14:06 -0800
Subject: [PATCH 3/3] add test case

---
 clang/test/AST/ast-dump-using.cpp | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/clang/test/AST/ast-dump-using.cpp 
b/clang/test/AST/ast-dump-using.cpp
index c007ecd8bda5839..5a4e910ffb8654e 100644
--- a/clang/test/AST/ast-dump-using.cpp
+++ b/clang/test/AST/ast-dump-using.cpp
@@ -12,7 +12,13 @@ using a::S;
 typedef S f; // to dump the introduced type
 // CHECK:  TypedefDecl
 // CHECK-NEXT: `-ElaboratedType {{.*}} 'S' sugar
-// CHECK-NEXT:   `-UsingType {{.*}} 'a::S' sugar
-// CHECK-NEXT: |-UsingShadow {{.*}} 'S'
+// CHECK-NEXT:   `-UsingType [[TYPE_ADDR:.*]] 'a::S' sugar
+// CHECK-NEXT: |-UsingShadow [[SHADOW_ADDR:.*]] 'S'
+// CHECK-NEXT: `-RecordType {{.*}} 'a::S'
+typedef S e; // check the same UsingType is reused.
+// CHECK:  TypedefDecl
+// CHECK-NEXT: `-ElaboratedType {{.*}} 'S' sugar
+// CHECK-NEXT:   `-UsingType [[TYPE_ADDR]] 'a::S' 

[clang] [clang] Make sure the same UsingType is searched and inserted (PR #79182)

2024-01-23 Thread Wei Wang via cfe-commits

apolloww wrote:

> The change is correct. The problem is subtle though. It comes from the 
> difference in behavior between the member and non-member Profile functions.
> 
> I think we could do better instead with a change which makes it harder to 
> trip on this.
> 
> I think a simplification like this should work (untested):
> 
> ```
> diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
> index ea425791fc97..3d411051084c 100644
> --- a/clang/include/clang/AST/Type.h
> +++ b/clang/include/clang/AST/Type.h
> @@ -4729,13 +4729,12 @@ public:
>bool typeMatchesDecl() const { return !UsingBits.hasTypeDifferentFromDecl; 
> }
> 
>void Profile(llvm::FoldingSetNodeID ) {
> -Profile(ID, Found, typeMatchesDecl() ? QualType() : getUnderlyingType());
> +Profile(ID, Found, getUnderlyingType());
>}
>static void Profile(llvm::FoldingSetNodeID , const UsingShadowDecl 
> *Found,
>QualType Underlying) {
>  ID.AddPointer(Found);
> -if (!Underlying.isNull())
> -  Underlying.Profile(ID);
> +Underlying.Profile(ID);
>}
>static bool classof(const Type *T) { return T->getTypeClass() == Using; }
>  };
> ```

Thanks. This works and looks better. 

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


[clang] [clang] Make sure the same UsingType is searched and inserted (PR #79182)

2024-01-23 Thread Wei Wang via cfe-commits

https://github.com/apolloww updated 
https://github.com/llvm/llvm-project/pull/79182

>From a542d63f472d799eb2d041c82cac402cfb8dec1a Mon Sep 17 00:00:00 2001
From: Wei Wang 
Date: Tue, 23 Jan 2024 10:01:57 -0800
Subject: [PATCH 1/2] [clang] Make sure the same UsingType is searched and
 inserted

---
 clang/lib/AST/ASTContext.cpp | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 5eb7aa3664569dd..d312ef61fb15d4a 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -4672,12 +4672,6 @@ QualType ASTContext::getTypedefType(const 
TypedefNameDecl *Decl,
 QualType ASTContext::getUsingType(const UsingShadowDecl *Found,
   QualType Underlying) const {
   llvm::FoldingSetNodeID ID;
-  UsingType::Profile(ID, Found, Underlying);
-
-  void *InsertPos = nullptr;
-  if (UsingType *T = UsingTypes.FindNodeOrInsertPos(ID, InsertPos))
-return QualType(T, 0);
-
   const Type *TypeForDecl =
   cast(Found->getTargetDecl())->getTypeForDecl();
 
@@ -4687,6 +4681,13 @@ QualType ASTContext::getUsingType(const UsingShadowDecl 
*Found,
 
   if (Underlying.getTypePtr() == TypeForDecl)
 Underlying = QualType();
+  UsingType::Profile(ID, Found, Underlying);
+
+  void *InsertPos = nullptr;
+  if (UsingType *T = UsingTypes.FindNodeOrInsertPos(ID, InsertPos)) {
+return QualType(T, 0);
+  }
+
   void *Mem =
   Allocate(UsingType::totalSizeToAlloc(!Underlying.isNull()),
alignof(UsingType));

>From 6dba099a2e1f06feb65248678a57bd00a3d4d0ae Mon Sep 17 00:00:00 2001
From: Wei Wang 
Date: Tue, 23 Jan 2024 19:58:24 -0800
Subject: [PATCH 2/2] update UsingType profile implementation

---
 clang/include/clang/AST/Type.h |  5 ++---
 clang/lib/AST/ASTContext.cpp   | 13 ++---
 2 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index ea425791fc97f05..3d411051084c71b 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -4729,13 +4729,12 @@ class UsingType final : public Type,
   bool typeMatchesDecl() const { return !UsingBits.hasTypeDifferentFromDecl; }
 
   void Profile(llvm::FoldingSetNodeID ) {
-Profile(ID, Found, typeMatchesDecl() ? QualType() : getUnderlyingType());
+Profile(ID, Found, getUnderlyingType());
   }
   static void Profile(llvm::FoldingSetNodeID , const UsingShadowDecl *Found,
   QualType Underlying) {
 ID.AddPointer(Found);
-if (!Underlying.isNull())
-  Underlying.Profile(ID);
+Underlying.Profile(ID);
   }
   static bool classof(const Type *T) { return T->getTypeClass() == Using; }
 };
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index d312ef61fb15d4a..5eb7aa3664569dd 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -4672,6 +4672,12 @@ QualType ASTContext::getTypedefType(const 
TypedefNameDecl *Decl,
 QualType ASTContext::getUsingType(const UsingShadowDecl *Found,
   QualType Underlying) const {
   llvm::FoldingSetNodeID ID;
+  UsingType::Profile(ID, Found, Underlying);
+
+  void *InsertPos = nullptr;
+  if (UsingType *T = UsingTypes.FindNodeOrInsertPos(ID, InsertPos))
+return QualType(T, 0);
+
   const Type *TypeForDecl =
   cast(Found->getTargetDecl())->getTypeForDecl();
 
@@ -4681,13 +4687,6 @@ QualType ASTContext::getUsingType(const UsingShadowDecl 
*Found,
 
   if (Underlying.getTypePtr() == TypeForDecl)
 Underlying = QualType();
-  UsingType::Profile(ID, Found, Underlying);
-
-  void *InsertPos = nullptr;
-  if (UsingType *T = UsingTypes.FindNodeOrInsertPos(ID, InsertPos)) {
-return QualType(T, 0);
-  }
-
   void *Mem =
   Allocate(UsingType::totalSizeToAlloc(!Underlying.isNull()),
alignof(UsingType));

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


[clang] [clang] Make sure the same UsingType is searched and inserted (PR #79182)

2024-01-23 Thread Wei Wang via cfe-commits

apolloww wrote:

We saw a huge build speed regression from internal codebase when migrating to 
clang-17 triggered by this issue. The search for the same `UsingType` always 
ends up with "not found" and the folding set `UsingTypes` contains lots of 
duplicated notes.  

This is a quick fix I come up with. Feel free to propose a better one because I 
don't work in clang front end often. If it looks good, I'll try to add a test 
case.   

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


[clang] [clang] Make sure the same UsingType is searched and inserted (PR #79182)

2024-01-23 Thread Wei Wang via cfe-commits

https://github.com/apolloww created 
https://github.com/llvm/llvm-project/pull/79182

When creating a new UsingType, the underlying type may change if it is a 
declaration. This creates an inconsistency between the type searched and type 
created. Move the update before search so that we always use the same type for 
search and creation. 

>From a542d63f472d799eb2d041c82cac402cfb8dec1a Mon Sep 17 00:00:00 2001
From: Wei Wang 
Date: Tue, 23 Jan 2024 10:01:57 -0800
Subject: [PATCH] [clang] Make sure the same UsingType is searched and inserted

---
 clang/lib/AST/ASTContext.cpp | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 5eb7aa3664569dd..d312ef61fb15d4a 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -4672,12 +4672,6 @@ QualType ASTContext::getTypedefType(const 
TypedefNameDecl *Decl,
 QualType ASTContext::getUsingType(const UsingShadowDecl *Found,
   QualType Underlying) const {
   llvm::FoldingSetNodeID ID;
-  UsingType::Profile(ID, Found, Underlying);
-
-  void *InsertPos = nullptr;
-  if (UsingType *T = UsingTypes.FindNodeOrInsertPos(ID, InsertPos))
-return QualType(T, 0);
-
   const Type *TypeForDecl =
   cast(Found->getTargetDecl())->getTypeForDecl();
 
@@ -4687,6 +4681,13 @@ QualType ASTContext::getUsingType(const UsingShadowDecl 
*Found,
 
   if (Underlying.getTypePtr() == TypeForDecl)
 Underlying = QualType();
+  UsingType::Profile(ID, Found, Underlying);
+
+  void *InsertPos = nullptr;
+  if (UsingType *T = UsingTypes.FindNodeOrInsertPos(ID, InsertPos)) {
+return QualType(T, 0);
+  }
+
   void *Mem =
   Allocate(UsingType::totalSizeToAlloc(!Underlying.isNull()),
alignof(UsingType));

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


[clang] [Clang] CGCoroutines skip emitting try block for value returning `noexcept` init `await_resume` calls (PR #73160)

2023-11-27 Thread Wei Wang via cfe-commits


@@ -129,7 +130,14 @@ static SmallString<32> buildSuspendPrefixStr(CGCoroData 
, AwaitKind Kind) {
   return Prefix;
 }
 
-static bool memberCallExpressionCanThrow(const Expr *E) {
+static bool ResumeExprCanThrow(const CoroutineSuspendExpr ) {
+  const Expr *E = S.getResumeExpr();
+
+  // If the return type of await_resume is not void, get the CXXMemberCallExpr
+  // from its subexpr.
+  if (const auto *BindTempExpr = dyn_cast(E)) {
+E = BindTempExpr->getSubExpr();
+  }

apolloww wrote:

I think we are only targeting the resume part of init_suspend here, so the 
cases are limited. Can we change the function name to something more specific, 
like `InitResumeExprCanThrow`?

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


[clang] [Clang] CGCoroutines skip emitting try block for value returning `noexcept` init `await_resume` calls (PR #73160)

2023-11-27 Thread Wei Wang via cfe-commits

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


[clang] [Clang] CGCoroutines skip emitting try block for value returning `noexcept` init `await_resume` calls (PR #73160)

2023-11-27 Thread Wei Wang via cfe-commits


@@ -129,7 +130,14 @@ static SmallString<32> buildSuspendPrefixStr(CGCoroData 
, AwaitKind Kind) {
   return Prefix;
 }
 
-static bool memberCallExpressionCanThrow(const Expr *E) {
+static bool ResumeExprCanThrow(const CoroutineSuspendExpr ) {
+  const Expr *E = S.getResumeExpr();
+
+  // If the return type of await_resume is not void, get the CXXMemberCallExpr
+  // from its subexpr.
+  if (const auto *BindTempExpr = dyn_cast(E)) {
+E = BindTempExpr->getSubExpr();
+  }

apolloww wrote:

I think we are only targeting the resume part of `init_suspend` here, so the 
cases are limited. Can we change the function name to something more specific, 
like `InitResumeExprCanThrow`?

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


[llvm] [clang] [Coroutines] Introduce [[clang::coro_only_destroy_when_complete]] (PR #71014)

2023-11-08 Thread Wei Wang via cfe-commits

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


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


[llvm] [clang] [Coroutines] Introduce [[clang::coro_only_destroy_when_complete]] (PR #71014)

2023-11-08 Thread Wei Wang via cfe-commits


@@ -0,0 +1,59 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 \
+// RUN: -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s
+
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 \
+// RUN: -O3 -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK-O
+
+#include "Inputs/coroutine.h"
+
+using namespace std;
+
+struct A;
+struct A_promise_type {
+  A get_return_object();
+  suspend_always initial_suspend();
+  suspend_always final_suspend() noexcept;
+  void return_value(int);
+  void unhandled_exception();
+
+  std::coroutine_handle<> handle;
+};
+
+struct Awaitable{
+  bool await_ready();
+  int await_resume();
+  template 
+  void await_suspend(F);
+};
+Awaitable something();
+
+struct dtor {
+dtor();
+~dtor();
+};
+
+struct [[clang::coro_only_destroy_when_complete]] A {

apolloww wrote:

Thanks for the explaination

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


[clang] [llvm] [Coroutines] Introduce [[clang::coro_only_destroy_when_complete]] (PR #71014)

2023-11-07 Thread Wei Wang via cfe-commits


@@ -0,0 +1,59 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 \
+// RUN: -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s
+
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 \
+// RUN: -O3 -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK-O
+
+#include "Inputs/coroutine.h"
+
+using namespace std;
+
+struct A;
+struct A_promise_type {
+  A get_return_object();
+  suspend_always initial_suspend();
+  suspend_always final_suspend() noexcept;
+  void return_value(int);
+  void unhandled_exception();
+
+  std::coroutine_handle<> handle;
+};
+
+struct Awaitable{
+  bool await_ready();
+  int await_resume();
+  template 
+  void await_suspend(F);
+};
+Awaitable something();
+
+struct dtor {
+dtor();
+~dtor();
+};
+
+struct [[clang::coro_only_destroy_when_complete]] A {

apolloww wrote:

Since the attribute is on the return type, would that mean it would apply to 
any coroutine returning the particular type? Say user is using some library 
implementation (i.e. `folly::coro::Task`), they would not be able to use the 
attribute because it would mark all the coroutines this way.

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


[clang-tools-extra] [mlir] [libcxx] [clang] [openmp] [llvm] [Clang] Warn against unused parameters in C++ coroutines with `-Wunused-parameters` (PR #70567)

2023-10-31 Thread Wei Wang via cfe-commits

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


[clang-tools-extra] [mlir] [libcxx] [clang] [openmp] [llvm] [Clang] Warn against unused parameters in C++ coroutines with `-Wunused-parameters` (PR #70567)

2023-10-31 Thread Wei Wang via cfe-commits

apolloww wrote:

> Thanks for looking into this. I haven't looked into the details. But I guess 
> it may be a good idea to teach `DiagnoseUnusedParameters` to understand 
> coroutines.

Yeah, I think it could also make user aware of unused parameters so

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


[openmp] [clang] [clang-tools-extra] [libcxx] [mlir] [llvm] [Clang] Warn against unused parameters in C++ coroutines with `-Wunused-parameters` (PR #70567)

2023-10-31 Thread Wei Wang via cfe-commits

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


[clang] [Clang][LLVM][Coroutines] Prevent __coro_gro from outliving __promise (PR #66706)

2023-09-21 Thread Wei Wang via cfe-commits

apolloww wrote:

Thanks for the fix! I think originally the deferred conversion is placed after 
`coro.end` so that it won't be counted as "use across suspend point", but it 
doesn't stop optimizer from breaking that assumption. 

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


[clang] ce7eb2e - [Coroutines] Avoid creating conditional cleanup markers in suspend block

2023-02-28 Thread Wei Wang via cfe-commits

Author: Wei Wang
Date: 2023-02-28T15:30:04-08:00
New Revision: ce7eb2e05544437af127684030a21b9e54a34f93

URL: 
https://github.com/llvm/llvm-project/commit/ce7eb2e05544437af127684030a21b9e54a34f93
DIFF: 
https://github.com/llvm/llvm-project/commit/ce7eb2e05544437af127684030a21b9e54a34f93.diff

LOG: [Coroutines] Avoid creating conditional cleanup markers in suspend block

We shouldn't access coro frame after returning from `await_suspend()` and 
before `llvm.coro.suspend()`.
Make sure we always hoist conditional cleanup markers when inside the 
`await.suspend` block.

Fix https://github.com/llvm/llvm-project/issues/59181

Reviewed By: ChuanqiXu

Differential Revision: https://reviews.llvm.org/D144680

Added: 
clang/test/CodeGenCoroutines/pr59181.cpp

Modified: 
clang/lib/CodeGen/CGCoroutine.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CodeGenFunction.h

Removed: 




diff  --git a/clang/lib/CodeGen/CGCoroutine.cpp 
b/clang/lib/CodeGen/CGCoroutine.cpp
index 775a4341558a..9b233c1807cf 100644
--- a/clang/lib/CodeGen/CGCoroutine.cpp
+++ b/clang/lib/CodeGen/CGCoroutine.cpp
@@ -198,7 +198,9 @@ static LValueOrRValue emitSuspendExpression(CodeGenFunction 
, CGCoroData 
   auto *NullPtr = llvm::ConstantPointerNull::get(CGF.CGM.Int8PtrTy);
   auto *SaveCall = Builder.CreateCall(CoroSave, {NullPtr});
 
+  CGF.CurCoro.InSuspendBlock = true;
   auto *SuspendRet = CGF.EmitScalarExpr(S.getSuspendExpr());
+  CGF.CurCoro.InSuspendBlock = false;
   if (SuspendRet != nullptr && SuspendRet->getType()->isIntegerTy(1)) {
 // Veto suspension if requested by bool returning await_suspend.
 BasicBlock *RealSuspendBlock =

diff  --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 052701c1ea18..a9116dd9c5b0 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -541,13 +541,17 @@ EmitMaterializeTemporaryExpr(const 
MaterializeTemporaryExpr *M) {
   // Avoid creating a conditional cleanup just to hold an llvm.lifetime.end
   // marker. Instead, start the lifetime of a conditional temporary earlier
   // so that it's unconditional. Don't do this with sanitizers which need
-  // more precise lifetime marks.
+  // more precise lifetime marks. However when inside an "await.suspend"
+  // block, we should always avoid conditional cleanup because it creates
+  // boolean marker that lives across await_suspend, which can destroy coro
+  // frame.
   ConditionalEvaluation *OldConditional = nullptr;
   CGBuilderTy::InsertPoint OldIP;
   if (isInConditionalBranch() && !E->getType().isDestructedType() &&
-  !SanOpts.has(SanitizerKind::HWAddress) &&
-  !SanOpts.has(SanitizerKind::Memory) &&
-  !CGM.getCodeGenOpts().SanitizeAddressUseAfterScope) {
+  ((!SanOpts.has(SanitizerKind::HWAddress) &&
+!SanOpts.has(SanitizerKind::Memory) &&
+!CGM.getCodeGenOpts().SanitizeAddressUseAfterScope) ||
+   inSuspendBlock())) {
 OldConditional = OutermostConditional;
 OutermostConditional = nullptr;
 

diff  --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index d7fef7ce5482..4298eb6c2b71 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -333,6 +333,7 @@ class CodeGenFunction : public CodeGenTypeCache {
   // in this header.
   struct CGCoroInfo {
 std::unique_ptr Data;
+bool InSuspendBlock = false;
 CGCoroInfo();
 ~CGCoroInfo();
   };
@@ -342,6 +343,10 @@ class CodeGenFunction : public CodeGenTypeCache {
 return CurCoro.Data != nullptr;
   }
 
+  bool inSuspendBlock() const {
+return isCoroutine() && CurCoro.InSuspendBlock;
+  }
+
   /// CurGD - The GlobalDecl for the current function being compiled.
   GlobalDecl CurGD;
 

diff  --git a/clang/test/CodeGenCoroutines/pr59181.cpp 
b/clang/test/CodeGenCoroutines/pr59181.cpp
new file mode 100644
index ..80f4634db252
--- /dev/null
+++ b/clang/test/CodeGenCoroutines/pr59181.cpp
@@ -0,0 +1,60 @@
+// Test for PR59181. Tests that no conditional cleanup is created around 
await_suspend.
+//
+// REQUIRES: x86-registered-target
+//
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o - 
-std=c++20 -disable-llvm-passes -fsanitize-address-use-after-scope | FileCheck 
%s
+
+#include "Inputs/coroutine.h"
+
+struct Task {
+  int value_;
+  struct promise_type {
+Task get_return_object() {
+  return Task{0};
+}
+
+std::suspend_never initial_suspend() noexcept {
+  return {};
+}
+
+std::suspend_never final_suspend() noexcept {
+  return {};
+}
+
+void return_value(Task t) noexcept {}
+void unhandled_exception() noexcept {}
+
+auto await_transform(Task t) {
+  struct Suspension {
+auto await_ready() noexcept { return false;}
+auto 

[clang] 55d887b - [time-trace] Add optimizer and codegen regions to NPM

2022-01-21 Thread Wei Wang via cfe-commits

Author: Wei Wang
Date: 2022-01-21T19:17:57-08:00
New Revision: 55d887b833646baeea0e3371fd2cbbd7550a8d4d

URL: 
https://github.com/llvm/llvm-project/commit/55d887b833646baeea0e3371fd2cbbd7550a8d4d
DIFF: 
https://github.com/llvm/llvm-project/commit/55d887b833646baeea0e3371fd2cbbd7550a8d4d.diff

LOG: [time-trace] Add optimizer and codegen regions to NPM

Optimizer and codegen regions were only added to legacy PM. Add
them to NPM as well.

Differential Revision: https://reviews.llvm.org/D117605

Added: 


Modified: 
clang/lib/CodeGen/BackendUtil.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 6b8e052305b49..9ae5c870afc81 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1492,8 +1492,11 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
   }
 
   // Now that we have all of the passes ready, run them.
-  PrettyStackTraceString CrashInfo("Optimizer");
-  MPM.run(*TheModule, MAM);
+  {
+PrettyStackTraceString CrashInfo("Optimizer");
+llvm::TimeTraceScope TimeScope("Optimizer");
+MPM.run(*TheModule, MAM);
+  }
 }
 
 void EmitAssemblyHelper::RunCodegenPipeline(
@@ -1525,8 +1528,11 @@ void EmitAssemblyHelper::RunCodegenPipeline(
 return;
   }
 
-  PrettyStackTraceString CrashInfo("Code generation");
-  CodeGenPasses.run(*TheModule);
+  {
+PrettyStackTraceString CrashInfo("Code generation");
+llvm::TimeTraceScope TimeScope("CodeGenPasses");
+CodeGenPasses.run(*TheModule);
+  }
 }
 
 /// A clean version of `EmitAssembly` that uses the new pass manager.



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


[clang] a075d67 - [Sema] fix nondeterminism in ASTContext::getDeducedTemplateSpecializationType

2021-11-19 Thread Wei Wang via cfe-commits

Author: Wei Wang
Date: 2021-11-19T13:22:07-08:00
New Revision: a075d67222832c234296ffd605f19e33023e6060

URL: 
https://github.com/llvm/llvm-project/commit/a075d67222832c234296ffd605f19e33023e6060
DIFF: 
https://github.com/llvm/llvm-project/commit/a075d67222832c234296ffd605f19e33023e6060.diff

LOG: [Sema] fix nondeterminism in 
ASTContext::getDeducedTemplateSpecializationType

`DeducedTemplateSpecializationTypes` is a 
`llvm::FoldingSet` [1],
where `FoldingSetNodeID` is based on the values: {`TemplateName`, `QualType`, 
`IsDeducedAsDependent`},
those values are also used as `DeducedTemplateSpecializationType` constructor 
arguments.

A `FoldingSetNodeID` created by the static 
`DeducedTemplateSpecializationType::Profile` may not be equal
to`FoldingSetNodeID` created by a member 
`DeducedTemplateSpecializationType::Profile` of an instance
created with the same {`TemplateName`, `QualType`, `IsDeducedAsDependent`}, 
which makes
`DeducedTemplateSpecializationTypes` lookups nondeterministic.

Specifically, while `IsDeducedAsDependent` value is passes to the constructor, 
`IsDependent()` method on
the created instance may return a different value, because `IsDependent` is not 
saved as is:
```name=clang/include/clang/AST/Type.h
  DeducedTemplateSpecializationType(TemplateName Template,  QualType 
DeducedAsType, bool IsDeducedAsDependent)
  : DeducedType(DeducedTemplateSpecialization, DeducedAsType,
toTypeDependence(Template.getDependence()) | // <~  also 
considers `TemplateName` parameter
(IsDeducedAsDependent ? 
TypeDependence::DependentInstantiation : TypeDependence::None)),
```
For example, if an instance A with key `FoldingSetNodeID {A, B, false}` is 
inserted. Then a key
`FoldingSetNodeID {A, B, true}` is probed:
If it happens to correspond to the same bucket in `FoldingSet` as the first 
key, and `A.Profile()` returns
`FoldingSetNodeID {A, B, true}`, then it's a hit.
If the bucket for the second key is different from the first key, instance A is 
not considered at all, and it's
a no hit, even if `A.Profile()` returns  `FoldingSetNodeID {A, B, true}`.

Since `TemplateName`, `QualType` parameter values involve memory pointers, the 
lookup result depend on allocator,
and may differ from run to run. When this is used as part of modules 
compilation, it may result in "module out of date"
errors, if imported modules are built on different machines.

This makes `ASTContext::getDeducedTemplateSpecializationType` consider 
`Template.isDependent()` similar
`DeducedTemplateSpecializationType` constructor.

Tested on a very big codebase, by running modules compilations from directories 
with varied path length
(seem to affect allocator seed).

1. https://llvm.org/docs/ProgrammersManual.html#llvm-adt-foldingset-h

Patch by Wei Wang and Igor Sugak!

Reviewed By: bruno

Differential Revision: https://reviews.llvm.org/D112481

Added: 


Modified: 
clang/include/clang/AST/Type.h
clang/lib/AST/ASTContext.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index fd25ec25d4f2..4c89c297bf34 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -5073,8 +5073,10 @@ class DeducedTemplateSpecializationType : public 
DeducedType,
   static void Profile(llvm::FoldingSetNodeID , TemplateName Template,
   QualType Deduced, bool IsDependent) {
 Template.Profile(ID);
-ID.AddPointer(Deduced.getAsOpaquePtr());
-ID.AddBoolean(IsDependent);
+QualType CanonicalType =
+Deduced.isNull() ? Deduced : Deduced.getCanonicalType();
+ID.AddPointer(CanonicalType.getAsOpaquePtr());
+ID.AddBoolean(IsDependent || Template.isDependent());
   }
 
   static bool classof(const Type *T) {

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index f0b931bdc905..294cc20f76c5 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -5676,6 +5676,9 @@ QualType ASTContext::getDeducedTemplateSpecializationType(
 
   auto *DTST = new (*this, TypeAlignment)
   DeducedTemplateSpecializationType(Template, DeducedType, IsDependent);
+  llvm::FoldingSetNodeID TempID;
+  DTST->Profile(TempID);
+  assert(ID == TempID && "ID does not match");
   Types.push_back(DTST);
   DeducedTemplateSpecializationTypes.InsertNode(DTST, InsertPos);
   return QualType(DTST, 0);



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


[clang] b283d55 - [openmp] Emit deferred diag only when device compilation presents

2021-10-25 Thread Wei Wang via cfe-commits

Author: Wei Wang
Date: 2021-10-25T11:19:18-07:00
New Revision: b283d55c90dd0b9495c9e91a76c2c62e587eb9b6

URL: 
https://github.com/llvm/llvm-project/commit/b283d55c90dd0b9495c9e91a76c2c62e587eb9b6
DIFF: 
https://github.com/llvm/llvm-project/commit/b283d55c90dd0b9495c9e91a76c2c62e587eb9b6.diff

LOG: [openmp] Emit deferred diag only when device compilation presents

There is no need to check for deferred diag when device compilation or target is
not given. This results in considerable build time improvement in some cases.

Differential Revision: https://reviews.llvm.org/D109175

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/test/OpenMP/declare_target_messages.cpp
clang/test/SemaCUDA/openmp-target.cu

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 1491407b0533c..69d2ef631872d 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -12609,7 +12609,9 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr 
*Init, bool DirectInit) {
 VDecl->setInitStyle(VarDecl::ListInit);
   }
 
-  if (LangOpts.OpenMP && VDecl->isFileVarDecl())
+  if (LangOpts.OpenMP &&
+  (LangOpts.OpenMPIsDevice || !LangOpts.OMPTargetTriples.empty()) &&
+  VDecl->isFileVarDecl())
 DeclsToCheckForDeferredDiags.insert(VDecl);
   CheckCompleteVariableDeclaration(VDecl);
 }
@@ -14839,7 +14841,9 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt 
*Body,
 DiscardCleanupsInEvaluationContext();
   }
 
-  if (FD && (LangOpts.OpenMP || LangOpts.CUDA || LangOpts.SYCLIsDevice)) {
+  if (FD && ((LangOpts.OpenMP && (LangOpts.OpenMPIsDevice ||
+  !LangOpts.OMPTargetTriples.empty())) ||
+ LangOpts.CUDA || LangOpts.SYCLIsDevice)) {
 auto ES = getEmissionStatus(FD);
 if (ES == Sema::FunctionEmissionStatus::Emitted ||
 ES == Sema::FunctionEmissionStatus::Unknown)

diff  --git a/clang/test/OpenMP/declare_target_messages.cpp 
b/clang/test/OpenMP/declare_target_messages.cpp
index b5ffe7bc698d1..1f608e927421d 100644
--- a/clang/test/OpenMP/declare_target_messages.cpp
+++ b/clang/test/OpenMP/declare_target_messages.cpp
@@ -1,11 +1,12 @@
 // RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp45 
-fopenmp -fopenmp-version=45 -fnoopenmp-use-tls -ferror-limit 100 -o - %s
-// RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 
-verify=expected,omp5,host5 -fopenmp -fnoopenmp-use-tls -ferror-limit 100 -o - 
%s
+// RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 
-verify=expected,omp5,host5 -fopenmp -fopenmp-targets=x86_64-apple-macos10.7.0 
-fnoopenmp-use-tls -ferror-limit 100 -o - %s
 // RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp5,dev5 
-fopenmp -fopenmp-is-device -fopenmp-targets=x86_64-apple-macos10.7.0 
-aux-triple x86_64-apple-macos10.7.0 -fnoopenmp-use-tls -ferror-limit 100 -o - 
%s
 
-// RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 
-verify=expected,omp5,host5 -fopenmp-simd -fnoopenmp-use-tls -ferror-limit 100 
-o - %s
-// RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 
-verify=expected,omp5,host5 -fopenmp-simd -fopenmp-is-device -fnoopenmp-use-tls 
-ferror-limit 100 -o - %s
+// RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 
-verify=expected,omp5,host5 -fopenmp-simd 
-fopenmp-targets=x86_64-apple-macos10.7.0 -fnoopenmp-use-tls -ferror-limit 100 
-o - %s
+// RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 
-verify=expected,omp5,host5 -fopenmp-simd -fopenmp-is-device 
-fopenmp-targets=x86_64-apple-macos10.7.0 -fnoopenmp-use-tls -ferror-limit 100 
-o - %s
 // RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp45 
-fopenmp-version=45 -fopenmp-simd -fnoopenmp-use-tls -ferror-limit 100 -o - %s
 
+// RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp5 
-fopenmp -fnoopenmp-use-tls -ferror-limit 100 -o - %s
 #pragma omp end declare target // expected-error {{unexpected OpenMP directive 
'#pragma omp end declare target'}}
 
 int a, b, z; // omp5-error {{variable captured in declare target region must 
appear in a to clause}}

diff  --git a/clang/test/SemaCUDA/openmp-target.cu 
b/clang/test/SemaCUDA/openmp-target.cu
index c32aed44fb624..6d22fa27c1952 100644
--- a/clang/test/SemaCUDA/openmp-target.cu
+++ b/clang/test/SemaCUDA/openmp-target.cu
@@ -1,8 +1,8 @@
 // RUN: %clang_cc1 -triple x86_64 -verify=expected,dev \
 // RUN:-verify-ignore-unexpected=note \
-// RUN:-fopenmp -fopenmp-version=50 -o - %s
+// RUN:-fopenmp -fopenmp-version=50 
-fopenmp-targets=amdgcn-amd-amdhsa -o - %s
 // RUN: %clang_cc1 -triple x86_64 -verify -verify-ignore-unexpected=note\
-// RUN:-fopenmp -fopenmp-version=50 -o - -x c++ %s
+// RUN:-fopenmp -fopenmp-version=50 
-fopenmp-targets=amdgcn-amd-amdhsa -o - -x c++ %s
 // RUN: %clang_cc1 -triple x86_64 -verify=dev -verify-ignore-unexpected=note\
 // 

[clang] e6b8320 - [clang][AST] Improve AST Reader/Writer memory footprint

2021-05-20 Thread Wei Wang via cfe-commits

Author: Wei Wang
Date: 2021-05-20T15:34:29-07:00
New Revision: e6b8320c0a634ba60c82693c6631ea90fb2988a6

URL: 
https://github.com/llvm/llvm-project/commit/e6b8320c0a634ba60c82693c6631ea90fb2988a6
DIFF: 
https://github.com/llvm/llvm-project/commit/e6b8320c0a634ba60c82693c6631ea90fb2988a6.diff

LOG: [clang][AST] Improve AST Reader/Writer memory footprint

Reduce memory footprint of AST Reader/Writer:
1. Adjust internal data containers' element type.
2. Switch to set for deduplication of deferred diags.

Differential Revision: https://reviews.llvm.org/D101793

Added: 


Modified: 
clang/include/clang/Sema/ExternalSemaSource.h
clang/include/clang/Sema/MultiplexExternalSemaSource.h
clang/include/clang/Sema/Sema.h
clang/include/clang/Serialization/ASTReader.h
clang/include/clang/Serialization/ASTWriter.h
clang/lib/Sema/MultiplexExternalSemaSource.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/ExternalSemaSource.h 
b/clang/include/clang/Sema/ExternalSemaSource.h
index 2854b4893484d..9c18aa1398d37 100644
--- a/clang/include/clang/Sema/ExternalSemaSource.h
+++ b/clang/include/clang/Sema/ExternalSemaSource.h
@@ -199,8 +199,8 @@ class ExternalSemaSource : public ExternalASTSource {
   /// and variable decls which may cause deferred diags. Note that this routine
   /// may be invoked multiple times; the external source should take care not 
to
   /// introduce the same declarations repeatedly.
-  virtual void ReadDeclsToCheckForDeferredDiags(
-  llvm::SmallVector ) {}
+  virtual void
+  ReadDeclsToCheckForDeferredDiags(llvm::SmallSetVector ) {}
 
   /// \copydoc Sema::CorrectTypo
   /// \note LookupKind must correspond to a valid Sema::LookupNameKind

diff  --git a/clang/include/clang/Sema/MultiplexExternalSemaSource.h 
b/clang/include/clang/Sema/MultiplexExternalSemaSource.h
index b54a6283d6408..78658dcf990c4 100644
--- a/clang/include/clang/Sema/MultiplexExternalSemaSource.h
+++ b/clang/include/clang/Sema/MultiplexExternalSemaSource.h
@@ -337,7 +337,7 @@ class MultiplexExternalSemaSource : public 
ExternalSemaSource {
   /// may be invoked multiple times; the external source should take care not 
to
   /// introduce the same declarations repeatedly.
   void ReadDeclsToCheckForDeferredDiags(
-  llvm::SmallVector ) override;
+  llvm::SmallSetVector ) override;
 
   /// \copydoc ExternalSemaSource::CorrectTypo
   /// \note Returns the first nonempty correction.

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 114ff6441b4a8..2ac6471c4f04a 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1786,7 +1786,7 @@ class Sema final {
   private:
 /// Function or variable declarations to be checked for whether the 
deferred
 /// diagnostics should be emitted.
-SmallVector DeclsToCheckForDeferredDiags;
+llvm::SmallSetVector DeclsToCheckForDeferredDiags;
 
   public:
   // Emit all deferred diagnostics.

diff  --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index 0df687c05366a..6932d9c86d0cc 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -767,21 +767,21 @@ class ASTReader
   /// This contains the data loaded from all EAGERLY_DESERIALIZED_DECLS blocks
   /// in the chain. The referenced declarations are deserialized and passed to
   /// the consumer eagerly.
-  SmallVector EagerlyDeserializedDecls;
+  SmallVector EagerlyDeserializedDecls;
 
   /// The IDs of all tentative definitions stored in the chain.
   ///
   /// Sema keeps track of all tentative definitions in a TU because it has to
   /// complete them and pass them on to CodeGen. Thus, tentative definitions in
   /// the PCH chain must be eagerly deserialized.
-  SmallVector TentativeDefinitions;
+  SmallVector TentativeDefinitions;
 
   /// The IDs of all CXXRecordDecls stored in the chain whose VTables are
   /// used.
   ///
   /// CodeGen has to emit VTables for these records, so they have to be eagerly
   /// deserialized.
-  SmallVector VTableUses;
+  SmallVector VTableUses;
 
   /// A snapshot of the pending instantiations in the chain.
   ///
@@ -789,7 +789,7 @@ class ASTReader
   /// end of the TU. It consists of a pair of values for every pending
   /// instantiation where the first value is the ID of the decl and the second
   /// is the instantiation location.
-  SmallVector PendingInstantiations;
+  SmallVector PendingInstantiations;
 
   //@}
 
@@ -799,24 +799,24 @@ class ASTReader
 
   /// A snapshot of Sema's unused file-scoped variable tracking, for
   /// generating warnings.
-  SmallVector UnusedFileScopedDecls;
+  SmallVector UnusedFileScopedDecls;
 
   /// A list of all the delegating constructors 

[clang] 93dc1b5 - [Remarks][2/2] Expand remarks hotness threshold option support in more tools

2020-11-30 Thread Wei Wang via cfe-commits

Author: Wei Wang
Date: 2020-11-30T21:55:50-08:00
New Revision: 93dc1b5b8cb2f85d0d347f39e49a7150accd4e70

URL: 
https://github.com/llvm/llvm-project/commit/93dc1b5b8cb2f85d0d347f39e49a7150accd4e70
DIFF: 
https://github.com/llvm/llvm-project/commit/93dc1b5b8cb2f85d0d347f39e49a7150accd4e70.diff

LOG: [Remarks][2/2] Expand remarks hotness threshold option support in more 
tools

This is the #2 of 2 changes that make remarks hotness threshold option
available in more tools. The changes also allow the threshold to sync with
hotness threshold from profile summary with special value 'auto'.

This change expands remarks hotness threshold option
-fdiagnostics-hotness-threshold in clang and *-remarks-hotness-threshold in
other tools to utilize hotness threshold from profile summary.

Remarks hotness filtering relies on several driver options. Table below lists
how different options are correlated and affect final remarks outputs:

| profile | hotness | threshold | remarks printed |
|-|-|---|-|
| No  | No  | No| All |
| No  | No  | Yes   | None|
| No  | Yes | No| All |
| No  | Yes | Yes   | None|
| Yes | No  | No| All |
| Yes | No  | Yes   | None|
| Yes | Yes | No| All |
| Yes | Yes | Yes   | >=threshold |

In the presence of profile summary, it is often more desirable to directly use
the hotness threshold from profile summary. The new argument value 'auto'
indicates threshold will be synced with hotness threshold from profile summary
during compilation. The "auto" threshold relies on the availability of profile
summary. In case of missing such information, no remarks will be generated.

Differential Revision: https://reviews.llvm.org/D85808

Added: 
clang/test/Frontend/Inputs/remarks-hotness.prof
clang/test/Frontend/remarks-hotness.cpp
llvm/test/Other/optimization-remarks-auto.ll
llvm/test/Transforms/SampleProfile/Inputs/remarks-hotness.prof
llvm/test/Transforms/SampleProfile/remarks-hotness.ll

Modified: 
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Basic/CodeGenOptions.h
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/Driver/opt-record.c
llvm/include/llvm/Analysis/ProfileSummaryInfo.h
llvm/include/llvm/IR/LLVMContext.h
llvm/include/llvm/IR/Module.h
llvm/lib/Analysis/OptimizationRemarkEmitter.cpp
llvm/lib/IR/LLVMContext.cpp
llvm/lib/IR/LLVMRemarkStreamer.cpp
llvm/lib/IR/Module.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 8c4a70ba4125..d4bbdbfa13b5 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -366,10 +366,6 @@ VALUE_CODEGENOPT(EmitCheckPathComponentsToStrip, 32, 0)
 /// Whether to report the hotness of the code region for optimization remarks.
 CODEGENOPT(DiagnosticsWithHotness, 1, 0)
 
-/// The minimum hotness value a diagnostic needs in order to be included in
-/// optimization diagnostics.
-VALUE_CODEGENOPT(DiagnosticsHotnessThreshold, 32, 0)
-
 /// Whether copy relocations support is available when building as PIE.
 CODEGENOPT(PIECopyRelocations, 1, 0)
 

diff  --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index e710c5792d76..5c540812ed31 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -346,6 +346,21 @@ class CodeGenOptions : public CodeGenOptionsBase {
   const char *Argv0 = nullptr;
   ArrayRef CommandLineArgs;
 
+  /// The minimum hotness value a diagnostic needs in order to be included in
+  /// optimization diagnostics.
+  ///
+  /// The threshold is an Optional value, which maps to one of the 3 states:
+  /// 1. 0=> threshold disabled. All remarks will be printed.
+  /// 2. positive int => manual threshold by user. Remarks with hotness exceed
+  ///threshold will be printed.
+  /// 3. None => 'auto' threshold by user. The actual value is not
+  ///available at command line, but will be synced with
+  ///hotness threshold from profile summary during
+  ///compilation.
+  ///
+  /// If threshold option is not specified, it is disabled by default.
+  Optional DiagnosticsHotnessThreshold = 0;
+
 public:
   // Define accessors/mutators for code generation options of enumeration type.
 #define CODEGENOPT(Name, Bits, Default)

diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 

[clang] c486870 - [clang] Pass-through remarks options to linker

2020-10-27 Thread Wei Wang via cfe-commits

Author: Wei Wang
Date: 2020-10-27T17:23:32-07:00
New Revision: c4868700c58078d0f4c71fab5af2bb73270d2d9f

URL: 
https://github.com/llvm/llvm-project/commit/c4868700c58078d0f4c71fab5af2bb73270d2d9f
DIFF: 
https://github.com/llvm/llvm-project/commit/c4868700c58078d0f4c71fab5af2bb73270d2d9f.diff

LOG: [clang] Pass-through remarks options to linker

Summary:
Propagate driver commandline remarks options to linker when LTO is enabled.

This gives novice user a convenient way to collect and filter remarks throughout
a typical toolchain invocation with sample profile and LTO using single switch
from the clang driver.

A typical use of this option from clang command-line:

* Using -Rpass* options to print remarks to screen:

  clang -fuse-ld=lld -flto=thin -fprofile-sample-use=foo_sample.txt
   -Rpass=inline -Rpass-missed=inline -Rpass-analysis=inline
   -fdiagnostics-show-hotness -fdiagnostics-hotness-threshold=100 -o foo foo.cpp

  Remarks will be dumped to screen from both pre-lto and lto
  compilation.

* Using serialized remarks options

  clang -fuse-ld=lld -flto=thin -fprofile-sample-use=foo_sample.txt
   -fsave-optimization-record
   -fdiagnostics-show-hotness -fdiagnostics-hotness-threshold=100 -o foo foo.cpp

  This will produce multiple yaml files containing optimization remarks:
  1. foo.opt.yaml : remarks from pre-lto
  2. foo.opt.ld.yaml.thin.1.yaml: remark during lto

  Differential Revision: https://reviews.llvm.org/D85810

Added: 


Modified: 
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/Driver/opt-record.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 23522e0886ff..d765b4cb598d 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -60,6 +60,62 @@ using namespace clang::driver::tools;
 using namespace clang;
 using namespace llvm::opt;
 
+static void renderRpassOptions(const ArgList , ArgStringList ) {
+  if (const Arg *A = Args.getLastArg(options::OPT_Rpass_EQ))
+CmdArgs.push_back(Args.MakeArgString(Twine("--plugin-opt=-pass-remarks=") +
+ A->getValue()));
+
+  if (const Arg *A = Args.getLastArg(options::OPT_Rpass_missed_EQ))
+CmdArgs.push_back(Args.MakeArgString(
+Twine("--plugin-opt=-pass-remarks-missed=") + A->getValue()));
+
+  if (const Arg *A = Args.getLastArg(options::OPT_Rpass_analysis_EQ))
+CmdArgs.push_back(Args.MakeArgString(
+Twine("--plugin-opt=-pass-remarks-analysis=") + A->getValue()));
+}
+
+static void renderRemarksOptions(const ArgList , ArgStringList ,
+ const llvm::Triple ,
+ const InputInfo ,
+ const InputInfo ) {
+  StringRef Format = "yaml";
+  if (const Arg *A = 
Args.getLastArg(options::OPT_fsave_optimization_record_EQ))
+Format = A->getValue();
+
+  SmallString<128> F;
+  const Arg *A = Args.getLastArg(options::OPT_foptimization_record_file_EQ);
+  if (A)
+F = A->getValue();
+  else if (Output.isFilename())
+F = Output.getFilename();
+
+  assert(!F.empty() && "Cannot determine remarks output name.");
+  // Append "opt.ld." to the end of the file name.
+  CmdArgs.push_back(
+  Args.MakeArgString(Twine("--plugin-opt=opt-remarks-filename=") + F +
+ Twine(".opt.ld.") + Format));
+
+  if (const Arg *A =
+  Args.getLastArg(options::OPT_foptimization_record_passes_EQ))
+CmdArgs.push_back(Args.MakeArgString(
+Twine("--plugin-opt=opt-remarks-passes=") + A->getValue()));
+
+  CmdArgs.push_back(Args.MakeArgString(
+  Twine("--plugin-opt=opt-remarks-format=") + Format.data()));
+}
+
+static void renderRemarksHotnessOptions(const ArgList ,
+ArgStringList ) {
+  if (Args.hasFlag(options::OPT_fdiagnostics_show_hotness,
+   options::OPT_fno_diagnostics_show_hotness, false))
+CmdArgs.push_back("--plugin-opt=opt-remarks-with-hotness");
+
+  if (const Arg *A =
+  Args.getLastArg(options::OPT_fdiagnostics_hotness_threshold_EQ))
+CmdArgs.push_back(Args.MakeArgString(
+Twine("--plugin-opt=opt-remarks-hotness-threshold=") + A->getValue()));
+}
+
 void tools::addPathIfExists(const Driver , const Twine ,
 ToolChain::path_list ) {
   if (D.getVFS().exists(Path))
@@ -552,6 +608,18 @@ void tools::addLTOOptions(const ToolChain , 
const ArgList ,
 Args.MakeArgString(Twine("-plugin-opt=stats-file=") + StatsFile));
 
   addX86AlignBranchArgs(D, Args, CmdArgs, /*IsLTO=*/true);
+
+  // Handle remark diagnostics on screen options: '-Rpass-*'.
+  renderRpassOptions(Args, CmdArgs);
+
+  // Handle serialized remarks options: '-fsave-optimization-record'
+  // and '-foptimization-record-*'.
+  if (willEmitRemarks(Args))
+