From 38e8b041294e858978e9659df4329cfe26059211 Mon Sep 17 00:00:00 2001
From: Hidehiko Abe <hidehiko@chromium.org>
Date: Fri, 28 Apr 2023 16:52:24 +0000
Subject: [PATCH] Reland "Enable PGO for Lacros."

This reverts commit 56a1c45082ed707949afd61ab53858a820648a30.

Reason for revert: profile data issue was addressed by crrev.com/c/4472554 so trying to reland.

The diff from the original CL.
- Enable only for amd64, because currently DUTs are dead. crbug.com/1435082
- Do not propagate afdo settings to Lacros binary build on ash bots.

Original change's description:
> Revert "Enable PGO for Lacros."
>
> This reverts commit bd7d36a7765d49ec9da3b4ffdb8b6dbf9a4f0568.
>
> Reason for revert: https://ci.chromium.org/ui/p/chrome/builders/ci/chromeos-jacuzzi-chrome/5494/overview
>
> Original change's description:
> > Enable PGO for Lacros.
> >
> > BUG=1410432
> > TEST=Ran locally.
> >
> > Change-Id: I1f339e639fc05725156e33cb238539c91beb9007
> > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4455907
> > Reviewed-by: Thomas Anderson <thomasanderson@chromium.org>
> > Reviewed-by: Sven Zheng <svenzheng@chromium.org>
> > Commit-Queue: Hidehiko Abe <hidehiko@chromium.org>
> > Cr-Commit-Position: refs/heads/main@{#1133892}
>
> Bug: 1410432
> Change-Id: I491ad2972cd9db67cce6056d63e62e8c4ab3bb5e
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4460134
> Reviewed-by: Darryl James <dljames@chromium.org>
> Commit-Queue: Sven Zheng <svenzheng@chromium.org>
> Owners-Override: Sven Zheng <svenzheng@chromium.org>
> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
> Reviewed-by: Sven Zheng <svenzheng@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#1134037}

Bug: 1410432
Change-Id: I7306a5bd929772b6fef2f03a29d51fa73f53432f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4483341
Commit-Queue: Hidehiko Abe <hidehiko@chromium.org>
Reviewed-by: Thomas Anderson <thomasanderson@chromium.org>
Reviewed-by: Sven Zheng <svenzheng@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1137222}
---
 build/config/compiler/pgo/pgo.gni | 8 +++++---
 build/toolchain/cros/BUILD.gn     | 7 +++++++
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/build/config/compiler/pgo/pgo.gni b/build/config/compiler/pgo/pgo.gni
index 9e9a0c524992a..02a2900ebabbe 100644
--- a/build/config/compiler/pgo/pgo.gni
+++ b/build/config/compiler/pgo/pgo.gni
@@ -19,13 +19,15 @@ declare_args() {
   # bad compile times.
   chrome_pgo_phase = 0
   if (!dcheck_always_on && is_official_build &&
-      # TODO(crbug.com/1052397): Remove chromeos_is_browser_only once
-      # target_os switch for lacros-chrome is completed.
       # TODO(crbug.com/1336055): Update this now-outdated condition with regard
       # to chromecast and determine whether chromeos_is_browser_only is
       # obsolete.
       (is_high_end_android || is_win || is_mac || is_fuchsia ||
-       (is_linux && !is_castos && !chromeos_is_browser_only))) {
+       (is_linux && !is_castos) ||
+       # TODO(crbug.com/1435082): Currently arm boards are not working.
+       # Enable this for arm boards, once the lab set up is fixed.
+       (is_chromeos_lacros && is_chromeos_device && target_cpu != "arm" &&
+        target_cpu != "arm64"))) {
     chrome_pgo_phase = 2
   }
 
diff --git a/build/toolchain/cros/BUILD.gn b/build/toolchain/cros/BUILD.gn
index c815e1ab2844a..12b82ee411f36 100644
--- a/build/toolchain/cros/BUILD.gn
+++ b/build/toolchain/cros/BUILD.gn
@@ -134,6 +134,7 @@ cros_toolchain("nacl_bootstrap") {
     cc = cros_nacl_helper_arm32_cc
     cxx = cros_nacl_helper_arm32_cxx
     ld = cros_nacl_helper_arm32_ld
+
     # Avoid accidental use of Arm64 sysroot because of SYSROOT
     # env variable set in ChromeOS builds.
     toolchain_args.sysroot = cros_nacl_helper_arm32_sysroot
@@ -278,6 +279,12 @@ if (also_build_lacros_chrome_for_architecture != "") {
       also_build_lacros_chrome_for_architecture = ""
       chromeos_is_browser_only = true
       use_clang_coverage = false
+
+      # Do not propagate AFDO settings from Ash build to Lacros build.
+      # Specifically, Lacros uses PGO by default, so this would
+      # conflict.
+      clang_use_default_sample_profile = false
+      clang_sample_profile_path = ""
     }
     if (!lacros_use_chromium_toolchain) {
       # These are args for the template.