[llvm-branch-commits] [llvm] [LLVM][Coroutines] Transform "coro_must_elide" calls to switch ABI coroutines to the `noalloc` variant (PR #99285)

2024-07-19 Thread Wei Wang via llvm-branch-commits


@@ -968,8 +969,8 @@ PassBuilder::buildInlinerPipeline(OptimizationLevel Level,
   // it's been modified since.
   MainCGPipeline.addPass(createCGSCCToFunctionPassAdaptor(
   RequireAnalysisPass()));
-
   MainCGPipeline.addPass(CoroSplitPass(Level != OptimizationLevel::O0));
+  MainCGPipeline.addPass(CoroAnnotationElidePass());

apolloww wrote:

There is another PR #90310 trying to move the coro passes into post-link 
pipeline if ThinLTO(`-flto=thin`) is enabled for the compilation. It ran into 
some issue with asan and going through some refactoring.

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


[llvm-branch-commits] [llvm] [LLVM][Coroutines] Transform "coro_must_elide" calls to switch ABI coroutines to the `noalloc` variant (PR #99285)

2024-07-22 Thread Wei Wang via llvm-branch-commits


@@ -968,8 +969,8 @@ PassBuilder::buildInlinerPipeline(OptimizationLevel Level,
   // it's been modified since.
   MainCGPipeline.addPass(createCGSCCToFunctionPassAdaptor(
   RequireAnalysisPass()));
-
   MainCGPipeline.addPass(CoroSplitPass(Level != OptimizationLevel::O0));
+  MainCGPipeline.addPass(CoroAnnotationElidePass());

apolloww wrote:

Yes, the pipeline will need to be adjusted for the new pass.

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


[llvm-branch-commits] [llvm] [LLVM][Coroutines] Create `.noalloc` variant of switch ABI coroutine ramp functions during CoroSplit (PR #99283)

2024-07-22 Thread Wei Wang via llvm-branch-commits


@@ -1455,6 +1462,64 @@ struct SwitchCoroutineSplitter {
 setCoroInfo(F, Shape, Clones);
   }
 
+  static Function *createNoAllocVariant(Function &F, coro::Shape &Shape,
+SmallVectorImpl &Clones) {
+auto *OrigFnTy = F.getFunctionType();
+auto OldParams = OrigFnTy->params();
+
+SmallVector NewParams;
+NewParams.reserve(OldParams.size() + 1);
+for (Type *T : OldParams) {
+  NewParams.push_back(T);
+}
+NewParams.push_back(PointerType::getUnqual(Shape.FrameTy));
+
+auto *NewFnTy = FunctionType::get(OrigFnTy->getReturnType(), NewParams,
+  OrigFnTy->isVarArg());
+Function *NoAllocF =
+Function::Create(NewFnTy, F.getLinkage(), F.getName() + ".noalloc");

apolloww wrote:

ThinLTO can import global values (variables and functions) from another 
modules. There would be a follow-up patch updating the pipeline so that 
coroutine passes are moved from pre-link to post-link. A previous attempt 
#90310 was blocked due to some conflict with Asan. I'll have a new version 
later. 

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


[llvm-branch-commits] [lld] 3acda91 - [Remarks][1/2] Expand remarks hotness threshold option support in more tools

2020-11-30 Thread Wei Wang via llvm-branch-commits

Author: Wei Wang
Date: 2020-11-30T21:55:49-08:00
New Revision: 3acda91742b7e995af87f1afaca5e0fa78669819

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

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

This is the #1 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 modifies the interface of lto::setupLLVMOptimizationRemarks() to
accept remarks hotness threshold. Update all the tools that use it with remarks
hotness threshold options:

* lld: '--opt-remarks-hotness-threshold='
* llvm-lto2: '--pass-remarks-hotness-threshold='
* llvm-lto: '--lto-pass-remarks-hotness-threshold='
* gold plugin: '-plugin-opt=opt-remarks-hotness-threshold='

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

Added: 
llvm/include/llvm/Remarks/HotnessThresholdParser.h

Modified: 
lld/ELF/Config.h
lld/ELF/Driver.cpp
lld/ELF/LTO.cpp
lld/ELF/Options.td
lld/test/ELF/lto/opt-remarks.ll
llvm/include/llvm/IR/LLVMContext.h
llvm/include/llvm/IR/LLVMRemarkStreamer.h
llvm/include/llvm/LTO/Config.h
llvm/include/llvm/LTO/LTO.h
llvm/include/llvm/Support/CommandLine.h
llvm/lib/IR/LLVMContext.cpp
llvm/lib/IR/LLVMContextImpl.h
llvm/lib/IR/LLVMRemarkStreamer.cpp
llvm/lib/LTO/LTO.cpp
llvm/lib/LTO/LTOBackend.cpp
llvm/lib/LTO/LTOCodeGenerator.cpp
llvm/lib/LTO/ThinLTOCodeGenerator.cpp
llvm/test/LTO/Resolution/X86/diagnostic-handler-remarks-with-hotness.ll
llvm/test/LTO/X86/diagnostic-handler-remarks-with-hotness.ll
llvm/test/tools/gold/X86/opt-remarks.ll
llvm/tools/gold/gold-plugin.cpp
llvm/tools/llc/llc.cpp
llvm/tools/llvm-lto2/llvm-lto2.cpp
llvm/tools/opt/opt.cpp

Removed: 




diff  --git a/lld/ELF/Config.h b/lld/ELF/Config.h
index 596188a33c5f..547e290c8939 100644
--- a/lld/ELF/Config.h
+++ b/lld/ELF/Config.h
@@ -111,6 +111,7 @@ struct Configuration {
   llvm::StringRef mapFile;
   llvm::StringRef outputFile;
   llvm::StringRef optRemarksFilename;
+  llvm::Optional optRemarksHotnessThreshold = 0;
   llvm::StringRef optRemarksPasses;
   llvm::StringRef optRemarksFormat;
   llvm::StringRef progName;

diff  --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index c3f3d88b5d2d..aa6fed652a93 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -48,6 +48,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/LTO/LTO.h"
+#include "llvm/Remarks/HotnessThresholdParser.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Compression.h"
 #include "llvm/Support/GlobPattern.h"
@@ -1013,6 +1014,17 @@ static void readConfigs(opt::InputArgList &args) {
   config->oFormatBinary = isOutputFormatBinary(args);
   config->omagic = args.hasFlag(OPT_omagic, OPT_no_omagic, false);
   config->optRemarksFilename = args.getLastArgValue(OPT_opt_remarks_filename);
+
+  // Parse remarks hotness threshold. Valid value is either integer or 'auto'.
+  if (auto *arg = args.getLastArg(OPT_opt_remarks_hotness_threshold)) {
+auto resultOrErr = remarks::parseHotnessThresholdOption(arg->getValue());
+if (!resultOrErr)
+  error(arg->getSpelling() + ": invalid argument '" + arg->getValue() +
+"', only integer or 'auto' is supported");
+else
+  config->optRemarksHotnessThreshold = *resultOrErr;
+  }
+
   config->optRemarksPasses = args.getLastArgValue(OPT_opt_remarks_passes);
   config->optRemarksWithHotness = args.hasArg(OPT_opt_remarks_with_hotness);
   config->optRemarksFormat = args.getLastArgValue(OPT_opt_remarks_format);

diff  --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp
index 30281a1541f1..24d7d9a07a9c 100644
--- a/lld/ELF/LTO.cpp
+++ b/lld/ELF/LTO.cpp
@@ -143,6 +143,7 @@ static lto::Config createConfig() {
   c.RemarksFilename = std::string(config->optRemarksFilename);
   c.RemarksPasses = std::string(config->optRemarksPasses);
   c.RemarksWithHotness = config->optRemarksWithHotness;
+  c.RemarksHotnessThreshold = config->optRemarksHotnessThreshold;
   c.RemarksFormat = std::string(config->optRemarksFormat);
 
   c.SampleProfile = std::string(config->ltoSampleProfile);

diff  --git a/lld/ELF/Options.td b/lld/ELF/Options.td
index f81f13d4d445..fc7089f63229 100644
--- a/lld/ELF/Options.td
+++ b/lld/ELF/Options.td
@@ -548,6 +548,10 @@ def disable_verify: F<"disable-verify">;
 defm mllvm: Eq<"mllvm", "Additional arguments to forward to LLVM's option 
processing">;
 def opt_remarks_filename: Separate<["--"], "opt-remarks-filename">,
   HelpText<"YAML output file for optimization remarks">;
+defm opt_remarks_hotness_threshold: EEq<"opt-remarks-hotness-threshold",
+  "Minimum profile count

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

2020-11-30 Thread Wei Wang via llvm-branch-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 814c3