[PATCH] D123297: [flang][driver] Add support for -mmlir

2022-04-14 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added inline comments.



Comment at: clang/include/clang/Driver/Options.td:3272
   MarshallingInfoStringVector>;
+def mmlir : Separate<["-"], "mmlir">,Flags<[CoreOption,FC1Option,FlangOption]>,
+  HelpText<"Additional arguments to forward to MLIR's option processing">;

MaskRay wrote:
> 
Thanks, included in the final version!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123297

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


[PATCH] D123297: [flang][driver] Add support for -mmlir

2022-04-14 Thread Andrzej Warzynski via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6c93e1d329e6: [flang][driver] Add support for `-mmlir` 
(authored by awarzynski).

Changed prior to commit:
  https://reviews.llvm.org/D123297?vs=422163=422787#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123297

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/FrontendOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/lib/FrontendTool/CMakeLists.txt
  flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/mllvm_vs_mmlir.f90

Index: flang/test/Driver/mllvm_vs_mmlir.f90
===
--- /dev/null
+++ flang/test/Driver/mllvm_vs_mmlir.f90
@@ -0,0 +1,19 @@
+! Verify that `-mllvm` options are forwarded to LLVM and `-mmlir` to MLIR.
+
+! In practice, '-mmlir --help' is a super-set of '-mllvm --help' and that limits what we can test here. With a better seperation of
+! LLVM, MLIR and Flang global options, we should be able to write a stricter test.
+
+!
+! RUN COMMAND
+!
+! RUN: %flang_fc1  -mmlir --help | FileCheck %s --check-prefix=MLIR
+! RUN: %flang_fc1  -mllvm --help | FileCheck %s --check-prefix=MLLVM
+
+!
+! EXPECTED OUTPUT
+!
+! MLIR: flang (MLIR option parsing) [options]
+! MLIR: --mlir-{{.*}}
+
+! MLLVM: flang (LLVM option parsing) [options]
+! MLLVM-NOT: --mlir-{{.*}}
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -48,6 +48,7 @@
 ! HELP-NEXT: -help  Display available options
 ! HELP-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-NEXT: -mllvm  Additional arguments to forward to LLVM's option processing
+! HELP-NEXT: -mmlir  Additional arguments to forward to MLIR's option processing
 ! HELP-NEXT: -module-dir   Put MODULE files in 
 ! HELP-NEXT: -nocpp Disable predefined and command line preprocessor macros
 ! HELP-NEXT: -o   Write output to 
@@ -124,6 +125,7 @@
 ! HELP-FC1-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-FC1-NEXT: -load Load the named plugin (dynamic shared object)
 ! HELP-FC1-NEXT: -mllvm  Additional arguments to forward to LLVM's option processing
+! HELP-FC1-NEXT: -mmlir  Additional arguments to forward to MLIR's option processing
 ! HELP-FC1-NEXT: -module-dir   Put MODULE files in 
 ! HELP-FC1-NEXT: -module-suffix  Use  as the suffix for module files (the default value is `.mod`)
 ! HELP-FC1-NEXT: -nocpp Disable predefined and command line preprocessor macros
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -48,6 +48,7 @@
 ! CHECK-NEXT: -help Display available options
 ! CHECK-NEXT: -IAdd directory to the end of the list of include search paths
 ! CHECK-NEXT: -mllvm  Additional arguments to forward to LLVM's option processing
+! CHECK-NEXT: -mmlir  Additional arguments to forward to MLIR's option processing
 ! CHECK-NEXT: -module-dir   Put MODULE files in 
 ! CHECK-NEXT: -nocpp Disable predefined and command line preprocessor macros
 ! CHECK-NEXT: -o  Write output to 
Index: flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -19,6 +19,8 @@
 #include "llvm/Option/Option.h"
 #include "llvm/Support/BuryPointer.h"
 #include "llvm/Support/CommandLine.h"
+#include "mlir/IR/MLIRContext.h"
+#include "mlir/Pass/PassManager.h"
 
 namespace Fortran::frontend {
 
@@ -150,6 +152,21 @@
 llvm::cl::ParseCommandLineOptions(numArgs + 1, args.get());
   }
 
+  // Honor -mmlir. This should happen AFTER plugins have been loaded!
+  if (!flang->frontendOpts().mlirArgs.empty()) {
+mlir::registerMLIRContextCLOptions();
+mlir::registerPassManagerCLOptions();
+unsigned numArgs = flang->frontendOpts().mlirArgs.size();
+auto args = std::make_unique(numArgs + 2);
+args[0] = "flang (MLIR option parsing)";
+
+for (unsigned i = 0; i != numArgs; ++i)
+  args[i + 1] = flang->frontendOpts().mlirArgs[i].c_str();
+
+args[numArgs + 1] = nullptr;
+llvm::cl::ParseCommandLineOptions(numArgs + 1, args.get());
+  }
+
   // If there were errors in 

[PATCH] D123297: [flang][driver] Add support for -mmlir

2022-04-13 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/include/clang/Driver/Options.td:3272
   MarshallingInfoStringVector>;
+def mmlir : Separate<["-"], "mmlir">,Flags<[CoreOption,FC1Option,FlangOption]>,
+  HelpText<"Additional arguments to forward to MLIR's option processing">;




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123297

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


[PATCH] D123297: [flang][driver] Add support for -mmlir

2022-04-13 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added inline comments.



Comment at: flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:15
+#include "mlir/IR/MLIRContext.h"
+#include "mlir/Pass/PassManager.h"
 #include "flang/Frontend/CompilerInstance.h"

rovka wrote:
> Nit: Should these come after the llvm/ headers? (So it's alphabetical except 
> for flang, which may go first)
Thanks, I will fix this before merging!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123297

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


[PATCH] D123297: [flang][driver] Add support for -mmlir

2022-04-13 Thread Diana Picus via Phabricator via cfe-commits
rovka accepted this revision.
rovka added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123297

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


[PATCH] D123297: [flang][driver] Add support for -mmlir

2022-04-12 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski updated this revision to Diff 422163.
awarzynski added a comment.

Rebase on top of `main`, re-fine the test

Make sure that the test file correctly takes into account that `-mmlir -help` 
is a superset of `-mllvm -help`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123297

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/FrontendOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/lib/FrontendTool/CMakeLists.txt
  flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/mllvm_vs_mmlir.f90

Index: flang/test/Driver/mllvm_vs_mmlir.f90
===
--- /dev/null
+++ flang/test/Driver/mllvm_vs_mmlir.f90
@@ -0,0 +1,16 @@
+! Verify that `-mllvm` options are forwarded to LLVM and `-mmlir` to MLIR
+
+!
+! RUN COMMAND
+!
+! RUN: %flang_fc1  -mmlir --help | FileCheck %s --check-prefix=MLIR
+! RUN: %flang_fc1  -mllvm --help | FileCheck %s --check-prefix=MLLVM
+
+!
+! EXPECTED OUTPUT
+!
+! MLIR: flang (MLIR option parsing) [options]
+! MLIR: --mlir-{{.*}}
+
+! MLLVM: flang (LLVM option parsing) [options]
+! MLLVM-NOT: --mlir-{{.*}}
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -48,6 +48,7 @@
 ! HELP-NEXT: -help  Display available options
 ! HELP-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-NEXT: -mllvm  Additional arguments to forward to LLVM's option processing
+! HELP-NEXT: -mmlir  Additional arguments to forward to MLIR's option processing
 ! HELP-NEXT: -module-dir   Put MODULE files in 
 ! HELP-NEXT: -nocpp Disable predefined and command line preprocessor macros
 ! HELP-NEXT: -o   Write output to 
@@ -123,6 +124,7 @@
 ! HELP-FC1-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-FC1-NEXT: -load Load the named plugin (dynamic shared object)
 ! HELP-FC1-NEXT: -mllvm  Additional arguments to forward to LLVM's option processing
+! HELP-FC1-NEXT: -mmlir  Additional arguments to forward to MLIR's option processing
 ! HELP-FC1-NEXT: -module-dir   Put MODULE files in 
 ! HELP-FC1-NEXT: -module-suffix  Use  as the suffix for module files (the default value is `.mod`)
 ! HELP-FC1-NEXT: -nocpp Disable predefined and command line preprocessor macros
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -48,6 +48,7 @@
 ! CHECK-NEXT: -help Display available options
 ! CHECK-NEXT: -IAdd directory to the end of the list of include search paths
 ! CHECK-NEXT: -mllvm  Additional arguments to forward to LLVM's option processing
+! CHECK-NEXT: -mmlir  Additional arguments to forward to MLIR's option processing
 ! CHECK-NEXT: -module-dir   Put MODULE files in 
 ! CHECK-NEXT: -nocpp Disable predefined and command line preprocessor macros
 ! CHECK-NEXT: -o  Write output to 
Index: flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -11,6 +11,8 @@
 //
 //===--===//
 
+#include "mlir/IR/MLIRContext.h"
+#include "mlir/Pass/PassManager.h"
 #include "flang/Frontend/CompilerInstance.h"
 #include "flang/Frontend/FrontendActions.h"
 #include "flang/Frontend/FrontendPluginRegistry.h"
@@ -148,6 +150,21 @@
 llvm::cl::ParseCommandLineOptions(numArgs + 1, args.get());
   }
 
+  // Honor -mmlir. This should happen AFTER plugins have been loaded!
+  if (!flang->frontendOpts().mlirArgs.empty()) {
+mlir::registerMLIRContextCLOptions();
+mlir::registerPassManagerCLOptions();
+unsigned numArgs = flang->frontendOpts().mlirArgs.size();
+auto args = std::make_unique(numArgs + 2);
+args[0] = "flang (MLIR option parsing)";
+
+for (unsigned i = 0; i != numArgs; ++i)
+  args[i + 1] = flang->frontendOpts().mlirArgs[i].c_str();
+
+args[numArgs + 1] = nullptr;
+llvm::cl::ParseCommandLineOptions(numArgs + 1, args.get());
+  }
+
   // If there were errors in processing arguments, don't do anything else.
   if (flang->diagnostics().hasErrorOccurred()) {
 return false;
Index: flang/lib/FrontendTool/CMakeLists.txt

[PATCH] D123297: [flang][driver] Add support for -mmlir

2022-04-12 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

I did a bit of digging and realised that MLIR llvm::cl options are lazily 
constructed on demand 

 (see the definition of options 

 in PassManagerOptions.cpp). This means that:

- Flang and LLVM global options are always visible and displayed when passing 
`-mllvm -help`,
- MLIR global options are only visible when explicitly initialised and 
displayed when passing `-mmlir -help`.

Since Flang and LLVM global options are always visible, llvm::cl will display 
them alongside MLIR options when using `-mmlir -help`. In other words,  `-mmlir 
-help` is a superset of `--mllvm -help`. This is not ideal, but we'd need to 
refactor all option definitions in Flang and LLVM to improve this. I suggesting 
leaving this for later.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123297

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


[PATCH] D123297: [flang][driver] Add support for -mmlir

2022-04-12 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added inline comments.



Comment at: flang/test/Driver/mllvm_vs_mmlir.f90:17
+! MLLVM: flang (LLVM option parsing) [options]
+! MLLVM: --print-ir-after-all
+! MLLVM-NOT: --mlir-{{.*}}

rovka wrote:
> awarzynski wrote:
> > awarzynski wrote:
> > > rriddle wrote:
> > > > awarzynski wrote:
> > > > > awarzynski wrote:
> > > > > > rovka wrote:
> > > > > > > rovka wrote:
> > > > > > > > Is this the most llvm-ish option we have? I'm concerned that 
> > > > > > > > MLIR might also decide to add an option that sounds like this 
> > > > > > > > (and for sure -print-ir-before-all is mentioned in the [[ 
> > > > > > > > https://mlir.llvm.org/getting_started/Debugging/ |  MLIR docs 
> > > > > > > > ]]).
> > > > > > > > Is this the most llvm-ish option we have? I'm concerned that 
> > > > > > > > MLIR might also decide to add an option that sounds like this 
> > > > > > > > (and for sure -print-ir-before-all is mentioned in the [[ 
> > > > > > > > https://mlir.llvm.org/getting_started/Debugging/ |  MLIR docs 
> > > > > > > > ]]).
> > > > > > > 
> > > > > > > Right, I think that might be why the premerge tests are failing...
> > > > > > > Is this the most llvm-ish option we have? 
> > > > > > 
> > > > > > Sadly, most LLVM options have rather generic names that could at 
> > > > > > some point be added in MLIR. Perhaps you'll spot something more 
> > > > > > suitable:
> > > > > > 
> > > > > > ```lang=bash
> > > > > > USAGE: flang (LLVM option parsing) [options]
> > > > > > 
> > > > > > OPTIONS:
> > > > > > 
> > > > > > Color Options:
> > > > > > 
> > > > > >   --color   - Use colors in 
> > > > > > output (default=autodetect)
> > > > > > 
> > > > > > General options:
> > > > > > 
> > > > > >   --aarch64-neon-syntax= - Choose style 
> > > > > > of NEON code to emit from AArch64 backend:
> > > > > > =generic-   Emit 
> > > > > > generic NEON assembly
> > > > > > =apple  -   Emit 
> > > > > > Apple-style NEON assembly
> > > > > >   --aarch64-use-aa  - Enable the 
> > > > > > use of AA during codegen.
> > > > > >   --abort-on-max-devirt-iterations-reached  - Abort when 
> > > > > > the max iterations for devirtualization CGSCC repeat pass is reached
> > > > > >   --allow-ginsert-as-artifact   - Allow 
> > > > > > G_INSERT to be considered an artifact. Hack around AMDGPU test 
> > > > > > infinite loops.
> > > > > >   --always-execute-loop-body- force the 
> > > > > > body of a loop to execute at least once
> > > > > >   --array-constructor-initial-buffer-size=- set the 
> > > > > > incremental array construction buffer size (default=32)
> > > > > >   --cfg-hide-cold-paths=- Hide blocks 
> > > > > > with relative frequency below the given value
> > > > > >   --cfg-hide-deoptimize-paths   -
> > > > > >   --cfg-hide-unreachable-paths  -
> > > > > >   --cost-kind=   - Target cost 
> > > > > > kind
> > > > > > =throughput -   Reciprocal 
> > > > > > throughput
> > > > > > =latency-   Instruction 
> > > > > > latency
> > > > > > =code-size  -   Code size
> > > > > > =size-latency   -   Code size 
> > > > > > and latency
> > > > > >   --debugify-level=  - Kind of debug 
> > > > > > info to add
> > > > > > =locations  -   Locations 
> > > > > > only
> > > > > > =location+variables -   Locations 
> > > > > > and Variables
> > > > > >   --debugify-quiet  - Suppress 
> > > > > > verbose debugify output
> > > > > >   --default-kinds= - string to set 
> > > > > > default kind values
> > > > > >   --disable-i2p-p2i-opt - Disables 
> > > > > > inttoptr/ptrtoint roundtrip optimization
> > > > > >   --dot-cfg-mssa= - file name for 
> > > > > > generated dot file
> > > > > >   --enable-cse-in-irtranslator  - Should enable 
> > > > > > CSE in irtranslator
> > > > > >   --enable-cse-in-legalizer - Should enable 
> > > > > > CSE in Legalizer
> > > > > >   --enable-gvn-memdep   -
> > > > > >   --enable-load-in-loop-pre -
> > > > > >   --enable-load-pre -
> > > > > >   --enable-loop-simplifycfg-term-folding-
> > > > > >   --enable-name-compression - Enable 
> > > > > > name/filename string compression
> > > > > >   --enable-split-backedge-in-load-pre   -
> > > > > >   

[PATCH] D123297: [flang][driver] Add support for -mmlir

2022-04-12 Thread Diana Picus via Phabricator via cfe-commits
rovka added inline comments.



Comment at: flang/test/Driver/mllvm_vs_mmlir.f90:17
+! MLLVM: flang (LLVM option parsing) [options]
+! MLLVM: --print-ir-after-all
+! MLLVM-NOT: --mlir-{{.*}}

awarzynski wrote:
> awarzynski wrote:
> > rriddle wrote:
> > > awarzynski wrote:
> > > > awarzynski wrote:
> > > > > rovka wrote:
> > > > > > rovka wrote:
> > > > > > > Is this the most llvm-ish option we have? I'm concerned that MLIR 
> > > > > > > might also decide to add an option that sounds like this (and for 
> > > > > > > sure -print-ir-before-all is mentioned in the [[ 
> > > > > > > https://mlir.llvm.org/getting_started/Debugging/ |  MLIR docs ]]).
> > > > > > > Is this the most llvm-ish option we have? I'm concerned that MLIR 
> > > > > > > might also decide to add an option that sounds like this (and for 
> > > > > > > sure -print-ir-before-all is mentioned in the [[ 
> > > > > > > https://mlir.llvm.org/getting_started/Debugging/ |  MLIR docs ]]).
> > > > > > 
> > > > > > Right, I think that might be why the premerge tests are failing...
> > > > > > Is this the most llvm-ish option we have? 
> > > > > 
> > > > > Sadly, most LLVM options have rather generic names that could at some 
> > > > > point be added in MLIR. Perhaps you'll spot something more suitable:
> > > > > 
> > > > > ```lang=bash
> > > > > USAGE: flang (LLVM option parsing) [options]
> > > > > 
> > > > > OPTIONS:
> > > > > 
> > > > > Color Options:
> > > > > 
> > > > >   --color   - Use colors in 
> > > > > output (default=autodetect)
> > > > > 
> > > > > General options:
> > > > > 
> > > > >   --aarch64-neon-syntax= - Choose style of 
> > > > > NEON code to emit from AArch64 backend:
> > > > > =generic-   Emit generic 
> > > > > NEON assembly
> > > > > =apple  -   Emit 
> > > > > Apple-style NEON assembly
> > > > >   --aarch64-use-aa  - Enable the use 
> > > > > of AA during codegen.
> > > > >   --abort-on-max-devirt-iterations-reached  - Abort when the 
> > > > > max iterations for devirtualization CGSCC repeat pass is reached
> > > > >   --allow-ginsert-as-artifact   - Allow G_INSERT 
> > > > > to be considered an artifact. Hack around AMDGPU test infinite loops.
> > > > >   --always-execute-loop-body- force the body 
> > > > > of a loop to execute at least once
> > > > >   --array-constructor-initial-buffer-size=- set the 
> > > > > incremental array construction buffer size (default=32)
> > > > >   --cfg-hide-cold-paths=- Hide blocks 
> > > > > with relative frequency below the given value
> > > > >   --cfg-hide-deoptimize-paths   -
> > > > >   --cfg-hide-unreachable-paths  -
> > > > >   --cost-kind=   - Target cost kind
> > > > > =throughput -   Reciprocal 
> > > > > throughput
> > > > > =latency-   Instruction 
> > > > > latency
> > > > > =code-size  -   Code size
> > > > > =size-latency   -   Code size and 
> > > > > latency
> > > > >   --debugify-level=  - Kind of debug 
> > > > > info to add
> > > > > =locations  -   Locations only
> > > > > =location+variables -   Locations and 
> > > > > Variables
> > > > >   --debugify-quiet  - Suppress 
> > > > > verbose debugify output
> > > > >   --default-kinds= - string to set 
> > > > > default kind values
> > > > >   --disable-i2p-p2i-opt - Disables 
> > > > > inttoptr/ptrtoint roundtrip optimization
> > > > >   --dot-cfg-mssa= - file name for 
> > > > > generated dot file
> > > > >   --enable-cse-in-irtranslator  - Should enable 
> > > > > CSE in irtranslator
> > > > >   --enable-cse-in-legalizer - Should enable 
> > > > > CSE in Legalizer
> > > > >   --enable-gvn-memdep   -
> > > > >   --enable-load-in-loop-pre -
> > > > >   --enable-load-pre -
> > > > >   --enable-loop-simplifycfg-term-folding-
> > > > >   --enable-name-compression - Enable 
> > > > > name/filename string compression
> > > > >   --enable-split-backedge-in-load-pre   -
> > > > >   --experimental-debug-variable-locations   - Use 
> > > > > experimental new value-tracking variable locations
> > > > >   --fdebug-dump-pre-fir - dump the 
> > > > > Pre-FIR tree prior to FIR generation
> > > > >   --fs-profile-debug-bw-threshold=- Only 

[PATCH] D123297: [flang][driver] Add support for -mmlir

2022-04-11 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added inline comments.



Comment at: flang/test/Driver/mllvm_vs_mmlir.f90:17
+! MLLVM: flang (LLVM option parsing) [options]
+! MLLVM: --print-ir-after-all
+! MLLVM-NOT: --mlir-{{.*}}

awarzynski wrote:
> rriddle wrote:
> > awarzynski wrote:
> > > awarzynski wrote:
> > > > rovka wrote:
> > > > > rovka wrote:
> > > > > > Is this the most llvm-ish option we have? I'm concerned that MLIR 
> > > > > > might also decide to add an option that sounds like this (and for 
> > > > > > sure -print-ir-before-all is mentioned in the [[ 
> > > > > > https://mlir.llvm.org/getting_started/Debugging/ |  MLIR docs ]]).
> > > > > > Is this the most llvm-ish option we have? I'm concerned that MLIR 
> > > > > > might also decide to add an option that sounds like this (and for 
> > > > > > sure -print-ir-before-all is mentioned in the [[ 
> > > > > > https://mlir.llvm.org/getting_started/Debugging/ |  MLIR docs ]]).
> > > > > 
> > > > > Right, I think that might be why the premerge tests are failing...
> > > > > Is this the most llvm-ish option we have? 
> > > > 
> > > > Sadly, most LLVM options have rather generic names that could at some 
> > > > point be added in MLIR. Perhaps you'll spot something more suitable:
> > > > 
> > > > ```lang=bash
> > > > USAGE: flang (LLVM option parsing) [options]
> > > > 
> > > > OPTIONS:
> > > > 
> > > > Color Options:
> > > > 
> > > >   --color   - Use colors in 
> > > > output (default=autodetect)
> > > > 
> > > > General options:
> > > > 
> > > >   --aarch64-neon-syntax= - Choose style of 
> > > > NEON code to emit from AArch64 backend:
> > > > =generic-   Emit generic 
> > > > NEON assembly
> > > > =apple  -   Emit 
> > > > Apple-style NEON assembly
> > > >   --aarch64-use-aa  - Enable the use of 
> > > > AA during codegen.
> > > >   --abort-on-max-devirt-iterations-reached  - Abort when the 
> > > > max iterations for devirtualization CGSCC repeat pass is reached
> > > >   --allow-ginsert-as-artifact   - Allow G_INSERT to 
> > > > be considered an artifact. Hack around AMDGPU test infinite loops.
> > > >   --always-execute-loop-body- force the body of 
> > > > a loop to execute at least once
> > > >   --array-constructor-initial-buffer-size=- set the 
> > > > incremental array construction buffer size (default=32)
> > > >   --cfg-hide-cold-paths=- Hide blocks with 
> > > > relative frequency below the given value
> > > >   --cfg-hide-deoptimize-paths   -
> > > >   --cfg-hide-unreachable-paths  -
> > > >   --cost-kind=   - Target cost kind
> > > > =throughput -   Reciprocal 
> > > > throughput
> > > > =latency-   Instruction 
> > > > latency
> > > > =code-size  -   Code size
> > > > =size-latency   -   Code size and 
> > > > latency
> > > >   --debugify-level=  - Kind of debug 
> > > > info to add
> > > > =locations  -   Locations only
> > > > =location+variables -   Locations and 
> > > > Variables
> > > >   --debugify-quiet  - Suppress verbose 
> > > > debugify output
> > > >   --default-kinds= - string to set 
> > > > default kind values
> > > >   --disable-i2p-p2i-opt - Disables 
> > > > inttoptr/ptrtoint roundtrip optimization
> > > >   --dot-cfg-mssa= - file name for 
> > > > generated dot file
> > > >   --enable-cse-in-irtranslator  - Should enable CSE 
> > > > in irtranslator
> > > >   --enable-cse-in-legalizer - Should enable CSE 
> > > > in Legalizer
> > > >   --enable-gvn-memdep   -
> > > >   --enable-load-in-loop-pre -
> > > >   --enable-load-pre -
> > > >   --enable-loop-simplifycfg-term-folding-
> > > >   --enable-name-compression - Enable 
> > > > name/filename string compression
> > > >   --enable-split-backedge-in-load-pre   -
> > > >   --experimental-debug-variable-locations   - Use experimental 
> > > > new value-tracking variable locations
> > > >   --fdebug-dump-pre-fir - dump the Pre-FIR 
> > > > tree prior to FIR generation
> > > >   --fs-profile-debug-bw-threshold=- Only show debug 
> > > > message if the source branch weight is greater  than this value.
> > > >   --fs-profile-debug-prob-diff-threshold= - Only show debug 
> > > > message if the branch 

[PATCH] D123297: [flang][driver] Add support for -mmlir

2022-04-07 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

In D123297#3436867 , @mehdi_amini 
wrote:

> `-mmlir` is fine with me, but note that MLIR has much less global options 
> than LLVM: you will only get access to context and passmanager options and 
> not individual passes flags. That's not a criticism :)
> (that's what makes it not likely to have conflicts by the way: the set of 
> MLIR option is well identified)

Thanks for taking a look! All this should be fine - the main rationale for this 
patch is to enable MLIR options in `flang-new` so that tests using `tco` or 
`bbc` (and which use MLIR options) can be ported to use `flang-new`. We were 
discussing this recently in https://reviews.llvm.org/D121171.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123297

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


[PATCH] D123297: [flang][driver] Add support for -mmlir

2022-04-07 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini added a comment.

`-mmlir` is fine with me, but note that MLIR has much less global options than 
LLVM: you will only get access to context and passmanager options and not 
individual passes flags. That's not a criticism :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123297

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


[PATCH] D123297: [flang][driver] Add support for -mmlir

2022-04-07 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added inline comments.



Comment at: flang/test/Driver/mllvm_vs_mmlir.f90:17
+! MLLVM: flang (LLVM option parsing) [options]
+! MLLVM: --print-ir-after-all
+! MLLVM-NOT: --mlir-{{.*}}

rriddle wrote:
> awarzynski wrote:
> > awarzynski wrote:
> > > rovka wrote:
> > > > rovka wrote:
> > > > > Is this the most llvm-ish option we have? I'm concerned that MLIR 
> > > > > might also decide to add an option that sounds like this (and for 
> > > > > sure -print-ir-before-all is mentioned in the [[ 
> > > > > https://mlir.llvm.org/getting_started/Debugging/ |  MLIR docs ]]).
> > > > > Is this the most llvm-ish option we have? I'm concerned that MLIR 
> > > > > might also decide to add an option that sounds like this (and for 
> > > > > sure -print-ir-before-all is mentioned in the [[ 
> > > > > https://mlir.llvm.org/getting_started/Debugging/ |  MLIR docs ]]).
> > > > 
> > > > Right, I think that might be why the premerge tests are failing...
> > > > Is this the most llvm-ish option we have? 
> > > 
> > > Sadly, most LLVM options have rather generic names that could at some 
> > > point be added in MLIR. Perhaps you'll spot something more suitable:
> > > 
> > > ```lang=bash
> > > USAGE: flang (LLVM option parsing) [options]
> > > 
> > > OPTIONS:
> > > 
> > > Color Options:
> > > 
> > >   --color   - Use colors in 
> > > output (default=autodetect)
> > > 
> > > General options:
> > > 
> > >   --aarch64-neon-syntax= - Choose style of 
> > > NEON code to emit from AArch64 backend:
> > > =generic-   Emit generic NEON 
> > > assembly
> > > =apple  -   Emit Apple-style 
> > > NEON assembly
> > >   --aarch64-use-aa  - Enable the use of 
> > > AA during codegen.
> > >   --abort-on-max-devirt-iterations-reached  - Abort when the max 
> > > iterations for devirtualization CGSCC repeat pass is reached
> > >   --allow-ginsert-as-artifact   - Allow G_INSERT to 
> > > be considered an artifact. Hack around AMDGPU test infinite loops.
> > >   --always-execute-loop-body- force the body of a 
> > > loop to execute at least once
> > >   --array-constructor-initial-buffer-size=- set the incremental 
> > > array construction buffer size (default=32)
> > >   --cfg-hide-cold-paths=- Hide blocks with 
> > > relative frequency below the given value
> > >   --cfg-hide-deoptimize-paths   -
> > >   --cfg-hide-unreachable-paths  -
> > >   --cost-kind=   - Target cost kind
> > > =throughput -   Reciprocal 
> > > throughput
> > > =latency-   Instruction 
> > > latency
> > > =code-size  -   Code size
> > > =size-latency   -   Code size and 
> > > latency
> > >   --debugify-level=  - Kind of debug info 
> > > to add
> > > =locations  -   Locations only
> > > =location+variables -   Locations and 
> > > Variables
> > >   --debugify-quiet  - Suppress verbose 
> > > debugify output
> > >   --default-kinds= - string to set 
> > > default kind values
> > >   --disable-i2p-p2i-opt - Disables 
> > > inttoptr/ptrtoint roundtrip optimization
> > >   --dot-cfg-mssa= - file name for 
> > > generated dot file
> > >   --enable-cse-in-irtranslator  - Should enable CSE 
> > > in irtranslator
> > >   --enable-cse-in-legalizer - Should enable CSE 
> > > in Legalizer
> > >   --enable-gvn-memdep   -
> > >   --enable-load-in-loop-pre -
> > >   --enable-load-pre -
> > >   --enable-loop-simplifycfg-term-folding-
> > >   --enable-name-compression - Enable 
> > > name/filename string compression
> > >   --enable-split-backedge-in-load-pre   -
> > >   --experimental-debug-variable-locations   - Use experimental 
> > > new value-tracking variable locations
> > >   --fdebug-dump-pre-fir - dump the Pre-FIR 
> > > tree prior to FIR generation
> > >   --fs-profile-debug-bw-threshold=- Only show debug 
> > > message if the source branch weight is greater  than this value.
> > >   --fs-profile-debug-prob-diff-threshold= - Only show debug 
> > > message if the branch probility is greater than this value (in 
> > > percentage).
> > >   --gen-array-coor  - in lowering create 
> > > ArrayCoorOp instead of CoordinateOp
> > >   

[PATCH] D123297: [flang][driver] Add support for -mmlir

2022-04-07 Thread River Riddle via Phabricator via cfe-commits
rriddle added inline comments.



Comment at: flang/test/Driver/mllvm_vs_mmlir.f90:17
+! MLLVM: flang (LLVM option parsing) [options]
+! MLLVM: --print-ir-after-all
+! MLLVM-NOT: --mlir-{{.*}}

awarzynski wrote:
> awarzynski wrote:
> > rovka wrote:
> > > rovka wrote:
> > > > Is this the most llvm-ish option we have? I'm concerned that MLIR might 
> > > > also decide to add an option that sounds like this (and for sure 
> > > > -print-ir-before-all is mentioned in the [[ 
> > > > https://mlir.llvm.org/getting_started/Debugging/ |  MLIR docs ]]).
> > > > Is this the most llvm-ish option we have? I'm concerned that MLIR might 
> > > > also decide to add an option that sounds like this (and for sure 
> > > > -print-ir-before-all is mentioned in the [[ 
> > > > https://mlir.llvm.org/getting_started/Debugging/ |  MLIR docs ]]).
> > > 
> > > Right, I think that might be why the premerge tests are failing...
> > > Is this the most llvm-ish option we have? 
> > 
> > Sadly, most LLVM options have rather generic names that could at some point 
> > be added in MLIR. Perhaps you'll spot something more suitable:
> > 
> > ```lang=bash
> > USAGE: flang (LLVM option parsing) [options]
> > 
> > OPTIONS:
> > 
> > Color Options:
> > 
> >   --color   - Use colors in output 
> > (default=autodetect)
> > 
> > General options:
> > 
> >   --aarch64-neon-syntax= - Choose style of NEON 
> > code to emit from AArch64 backend:
> > =generic-   Emit generic NEON 
> > assembly
> > =apple  -   Emit Apple-style 
> > NEON assembly
> >   --aarch64-use-aa  - Enable the use of AA 
> > during codegen.
> >   --abort-on-max-devirt-iterations-reached  - Abort when the max 
> > iterations for devirtualization CGSCC repeat pass is reached
> >   --allow-ginsert-as-artifact   - Allow G_INSERT to be 
> > considered an artifact. Hack around AMDGPU test infinite loops.
> >   --always-execute-loop-body- force the body of a 
> > loop to execute at least once
> >   --array-constructor-initial-buffer-size=- set the incremental 
> > array construction buffer size (default=32)
> >   --cfg-hide-cold-paths=- Hide blocks with 
> > relative frequency below the given value
> >   --cfg-hide-deoptimize-paths   -
> >   --cfg-hide-unreachable-paths  -
> >   --cost-kind=   - Target cost kind
> > =throughput -   Reciprocal 
> > throughput
> > =latency-   Instruction latency
> > =code-size  -   Code size
> > =size-latency   -   Code size and 
> > latency
> >   --debugify-level=  - Kind of debug info to 
> > add
> > =locations  -   Locations only
> > =location+variables -   Locations and 
> > Variables
> >   --debugify-quiet  - Suppress verbose 
> > debugify output
> >   --default-kinds= - string to set default 
> > kind values
> >   --disable-i2p-p2i-opt - Disables 
> > inttoptr/ptrtoint roundtrip optimization
> >   --dot-cfg-mssa= - file name for 
> > generated dot file
> >   --enable-cse-in-irtranslator  - Should enable CSE in 
> > irtranslator
> >   --enable-cse-in-legalizer - Should enable CSE in 
> > Legalizer
> >   --enable-gvn-memdep   -
> >   --enable-load-in-loop-pre -
> >   --enable-load-pre -
> >   --enable-loop-simplifycfg-term-folding-
> >   --enable-name-compression - Enable name/filename 
> > string compression
> >   --enable-split-backedge-in-load-pre   -
> >   --experimental-debug-variable-locations   - Use experimental new 
> > value-tracking variable locations
> >   --fdebug-dump-pre-fir - dump the Pre-FIR tree 
> > prior to FIR generation
> >   --fs-profile-debug-bw-threshold=- Only show debug 
> > message if the source branch weight is greater  than this value.
> >   --fs-profile-debug-prob-diff-threshold= - Only show debug 
> > message if the branch probility is greater than this value (in percentage).
> >   --gen-array-coor  - in lowering create 
> > ArrayCoorOp instead of CoordinateOp
> >   --generate-merged-base-profiles   - When generating 
> > nested context-sensitive profiles, always generate extra base profile for 
> > function with all its context profiles merged into it.
> >   --inline-all   

[PATCH] D123297: [flang][driver] Add support for -mmlir

2022-04-07 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski updated this revision to Diff 421223.
awarzynski added a comment.

Make sure the MLIR CL options are "applied"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123297

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/FrontendOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/lib/FrontendTool/CMakeLists.txt
  flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/mllvm_vs_mmlir.f90

Index: flang/test/Driver/mllvm_vs_mmlir.f90
===
--- /dev/null
+++ flang/test/Driver/mllvm_vs_mmlir.f90
@@ -0,0 +1,18 @@
+! Verify that `-mllvm` options are forwarded to LLVM and `-mmlir` to MLIR
+
+!
+! RUN COMMAND
+!
+! RUN: %flang_fc1  -mmlir --help | FileCheck %s --check-prefix=MLIR
+! RUN: %flang_fc1  -mllvm --help | FileCheck %s --check-prefix=MLLVM
+
+!
+! EXPECTED OUTPUT
+!
+! MLIR: flang (MLIR option parsing) [options]
+! MLIR: --mlir-{{.*}}
+! MLIR-NOT: --mir-strip-debugify-only
+
+! MLLVM: flang (LLVM option parsing) [options]
+! MLLVM: --mir-strip-debugify-only
+! MLLVM-NOT: --mlir-{{.*}}
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -48,6 +48,7 @@
 ! HELP-NEXT: -help  Display available options
 ! HELP-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-NEXT: -mllvm  Additional arguments to forward to LLVM's option processing
+! HELP-NEXT: -mmlir  Additional arguments to forward to MLIR's option processing
 ! HELP-NEXT: -module-dir   Put MODULE files in 
 ! HELP-NEXT: -nocpp Disable predefined and command line preprocessor macros
 ! HELP-NEXT: -o   Write output to 
@@ -123,6 +124,7 @@
 ! HELP-FC1-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-FC1-NEXT: -load Load the named plugin (dynamic shared object)
 ! HELP-FC1-NEXT: -mllvm  Additional arguments to forward to LLVM's option processing
+! HELP-FC1-NEXT: -mmlir  Additional arguments to forward to MLIR's option processing
 ! HELP-FC1-NEXT: -module-dir   Put MODULE files in 
 ! HELP-FC1-NEXT: -module-suffix  Use  as the suffix for module files (the default value is `.mod`)
 ! HELP-FC1-NEXT: -nocpp Disable predefined and command line preprocessor macros
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -48,6 +48,7 @@
 ! CHECK-NEXT: -help Display available options
 ! CHECK-NEXT: -IAdd directory to the end of the list of include search paths
 ! CHECK-NEXT: -mllvm  Additional arguments to forward to LLVM's option processing
+! CHECK-NEXT: -mmlir  Additional arguments to forward to MLIR's option processing
 ! CHECK-NEXT: -module-dir   Put MODULE files in 
 ! CHECK-NEXT: -nocpp Disable predefined and command line preprocessor macros
 ! CHECK-NEXT: -o  Write output to 
Index: flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -11,6 +11,8 @@
 //
 //===--===//
 
+#include "mlir/IR/MLIRContext.h"
+#include "mlir/Pass/PassManager.h"
 #include "flang/Frontend/CompilerInstance.h"
 #include "flang/Frontend/FrontendActions.h"
 #include "flang/Frontend/FrontendPluginRegistry.h"
@@ -148,6 +150,21 @@
 llvm::cl::ParseCommandLineOptions(numArgs + 1, args.get());
   }
 
+  // Honor -mmlir. This should happen AFTER plugins have been loaded!
+  if (!flang->frontendOpts().mlirArgs.empty()) {
+mlir::registerMLIRContextCLOptions();
+mlir::registerPassManagerCLOptions();
+unsigned numArgs = flang->frontendOpts().mlirArgs.size();
+auto args = std::make_unique(numArgs + 2);
+args[0] = "flang (MLIR option parsing)";
+
+for (unsigned i = 0; i != numArgs; ++i)
+  args[i + 1] = flang->frontendOpts().mlirArgs[i].c_str();
+
+args[numArgs + 1] = nullptr;
+llvm::cl::ParseCommandLineOptions(numArgs + 1, args.get());
+  }
+
   // If there were errors in processing arguments, don't do anything else.
   if (flang->diagnostics().hasErrorOccurred()) {
 return false;
Index: flang/lib/FrontendTool/CMakeLists.txt

[PATCH] D123297: [flang][driver] Add support for -mmlir

2022-04-07 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

In D123297#3435816 , @rovka wrote:

> I don't know the command line library that well, so I have this curiosity: 
> what happens if LLVM and MLIR have 2 different options with the same name? Do 
> we get a compile time error?

The llvm::cl API uses global variables. So, if a variable is defined twice, you 
will get a compilation error. I will advertise this before merging so that 
folks from LLVM and MLIR are aware of this change. I'm hoping that they won't 
mind having to use distinct variable names for CL options in MLIR and LLVM.

> Or is there a risk that someone might -mllvm -XYZ and it would end up in 
> MLIR's XYZ option instead, because we're processing the MLIR options after 
> the LLVM ones?

Note that `-mllvm` options are saved in `llvmArgs` and `-mmlir` options are 
saved in `mlirArgs` (this is taken care of in "CompilerInvocation.cpp"). This 
should guarantee that the right option set is used.




Comment at: flang/test/Driver/mllvm_vs_mmlir.f90:17
+! MLLVM: flang (LLVM option parsing) [options]
+! MLLVM: --print-ir-after-all
+! MLLVM-NOT: --mlir-{{.*}}

rovka wrote:
> rovka wrote:
> > Is this the most llvm-ish option we have? I'm concerned that MLIR might 
> > also decide to add an option that sounds like this (and for sure 
> > -print-ir-before-all is mentioned in the [[ 
> > https://mlir.llvm.org/getting_started/Debugging/ |  MLIR docs ]]).
> > Is this the most llvm-ish option we have? I'm concerned that MLIR might 
> > also decide to add an option that sounds like this (and for sure 
> > -print-ir-before-all is mentioned in the [[ 
> > https://mlir.llvm.org/getting_started/Debugging/ |  MLIR docs ]]).
> 
> Right, I think that might be why the premerge tests are failing...
> Is this the most llvm-ish option we have? 

Sadly, most LLVM options have rather generic names that could at some point be 
added in MLIR. Perhaps you'll spot something more suitable:

```lang=bash
USAGE: flang (LLVM option parsing) [options]

OPTIONS:

Color Options:

  --color   - Use colors in output 
(default=autodetect)

General options:

  --aarch64-neon-syntax= - Choose style of NEON code 
to emit from AArch64 backend:
=generic-   Emit generic NEON 
assembly
=apple  -   Emit Apple-style NEON 
assembly
  --aarch64-use-aa  - Enable the use of AA 
during codegen.
  --abort-on-max-devirt-iterations-reached  - Abort when the max 
iterations for devirtualization CGSCC repeat pass is reached
  --allow-ginsert-as-artifact   - Allow G_INSERT to be 
considered an artifact. Hack around AMDGPU test infinite loops.
  --always-execute-loop-body- force the body of a loop 
to execute at least once
  --array-constructor-initial-buffer-size=- set the incremental array 
construction buffer size (default=32)
  --cfg-hide-cold-paths=- Hide blocks with relative 
frequency below the given value
  --cfg-hide-deoptimize-paths   -
  --cfg-hide-unreachable-paths  -
  --cost-kind=   - Target cost kind
=throughput -   Reciprocal throughput
=latency-   Instruction latency
=code-size  -   Code size
=size-latency   -   Code size and latency
  --debugify-level=  - Kind of debug info to add
=locations  -   Locations only
=location+variables -   Locations and Variables
  --debugify-quiet  - Suppress verbose debugify 
output
  --default-kinds= - string to set default 
kind values
  --disable-i2p-p2i-opt - Disables 
inttoptr/ptrtoint roundtrip optimization
  --dot-cfg-mssa= - file name for generated 
dot file
  --enable-cse-in-irtranslator  - Should enable CSE in 
irtranslator
  --enable-cse-in-legalizer - Should enable CSE in 
Legalizer
  --enable-gvn-memdep   -
  --enable-load-in-loop-pre -
  --enable-load-pre -
  --enable-loop-simplifycfg-term-folding-
  --enable-name-compression - Enable name/filename 
string compression
  --enable-split-backedge-in-load-pre   -
  --experimental-debug-variable-locations   - Use experimental new 
value-tracking variable locations
  --fdebug-dump-pre-fir - dump the Pre-FIR tree 
prior to FIR generation
  --fs-profile-debug-bw-threshold=- Only show debug 

[PATCH] D123297: [flang][driver] Add support for -mmlir

2022-04-07 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski updated this revision to Diff 421168.
awarzynski edited the summary of this revision.
awarzynski added a comment.

Fix pre-commit CI


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123297

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/FrontendOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/FrontendTool/CMakeLists.txt
  flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/mllvm_vs_mmlir.f90

Index: flang/test/Driver/mllvm_vs_mmlir.f90
===
--- /dev/null
+++ flang/test/Driver/mllvm_vs_mmlir.f90
@@ -0,0 +1,18 @@
+! Verify that `-mllvm` options are forwarded to LLVM and `-mmlir` to MLIR
+
+!
+! RUN COMMAND
+!
+! RUN: %flang_fc1  -mmlir --help | FileCheck %s --check-prefix=MLIR
+! RUN: %flang_fc1  -mllvm --help | FileCheck %s --check-prefix=MLLVM
+
+!
+! EXPECTED OUTPUT
+!
+! MLIR: flang (MLIR option parsing) [options]
+! MLIR: --mlir-{{.*}}
+! MLIR-NOT: --mir-strip-debugify-only
+
+! MLLVM: flang (LLVM option parsing) [options]
+! MLLVM: --mir-strip-debugify-only
+! MLLVM-NOT: --mlir-{{.*}}
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -48,6 +48,7 @@
 ! HELP-NEXT: -help  Display available options
 ! HELP-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-NEXT: -mllvm  Additional arguments to forward to LLVM's option processing
+! HELP-NEXT: -mmlir  Additional arguments to forward to MLIR's option processing
 ! HELP-NEXT: -module-dir   Put MODULE files in 
 ! HELP-NEXT: -nocpp Disable predefined and command line preprocessor macros
 ! HELP-NEXT: -o   Write output to 
@@ -123,6 +124,7 @@
 ! HELP-FC1-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-FC1-NEXT: -load Load the named plugin (dynamic shared object)
 ! HELP-FC1-NEXT: -mllvm  Additional arguments to forward to LLVM's option processing
+! HELP-FC1-NEXT: -mmlir  Additional arguments to forward to MLIR's option processing
 ! HELP-FC1-NEXT: -module-dir   Put MODULE files in 
 ! HELP-FC1-NEXT: -module-suffix  Use  as the suffix for module files (the default value is `.mod`)
 ! HELP-FC1-NEXT: -nocpp Disable predefined and command line preprocessor macros
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -48,6 +48,7 @@
 ! CHECK-NEXT: -help Display available options
 ! CHECK-NEXT: -IAdd directory to the end of the list of include search paths
 ! CHECK-NEXT: -mllvm  Additional arguments to forward to LLVM's option processing
+! CHECK-NEXT: -mmlir  Additional arguments to forward to MLIR's option processing
 ! CHECK-NEXT: -module-dir   Put MODULE files in 
 ! CHECK-NEXT: -nocpp Disable predefined and command line preprocessor macros
 ! CHECK-NEXT: -o  Write output to 
Index: flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -11,6 +11,8 @@
 //
 //===--===//
 
+#include "mlir/IR/MLIRContext.h"
+#include "mlir/Pass/PassManager.h"
 #include "flang/Frontend/CompilerInstance.h"
 #include "flang/Frontend/FrontendActions.h"
 #include "flang/Frontend/FrontendPluginRegistry.h"
@@ -148,6 +150,21 @@
 llvm::cl::ParseCommandLineOptions(numArgs + 1, args.get());
   }
 
+  // Honor -mmlir. This should happen AFTER plugins have been loaded!
+  if (!flang->frontendOpts().mlirArgs.empty()) {
+mlir::registerMLIRContextCLOptions();
+mlir::registerPassManagerCLOptions();
+unsigned numArgs = flang->frontendOpts().mlirArgs.size();
+auto args = std::make_unique(numArgs + 2);
+args[0] = "flang (MLIR option parsing)";
+
+for (unsigned i = 0; i != numArgs; ++i)
+  args[i + 1] = flang->frontendOpts().mlirArgs[i].c_str();
+
+args[numArgs + 1] = nullptr;
+llvm::cl::ParseCommandLineOptions(numArgs + 1, args.get());
+  }
+
   // If there were errors in processing arguments, don't do anything else.
   if (flang->diagnostics().hasErrorOccurred()) {
 return false;
Index: flang/lib/FrontendTool/CMakeLists.txt

[PATCH] D123297: [flang][driver] Add support for -mmlir

2022-04-07 Thread Diana Picus via Phabricator via cfe-commits
rovka added inline comments.



Comment at: flang/test/Driver/mllvm_vs_mmlir.f90:17
+! MLLVM: flang (LLVM option parsing) [options]
+! MLLVM: --print-ir-after-all
+! MLLVM-NOT: --mlir-{{.*}}

rovka wrote:
> Is this the most llvm-ish option we have? I'm concerned that MLIR might also 
> decide to add an option that sounds like this (and for sure 
> -print-ir-before-all is mentioned in the [[ 
> https://mlir.llvm.org/getting_started/Debugging/ |  MLIR docs ]]).
> Is this the most llvm-ish option we have? I'm concerned that MLIR might also 
> decide to add an option that sounds like this (and for sure 
> -print-ir-before-all is mentioned in the [[ 
> https://mlir.llvm.org/getting_started/Debugging/ |  MLIR docs ]]).

Right, I think that might be why the premerge tests are failing...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123297

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


[PATCH] D123297: [flang][driver] Add support for -mmlir

2022-04-07 Thread Diana Picus via Phabricator via cfe-commits
rovka added a comment.

I don't know the command line library that well, so I have this curiosity: what 
happens if LLVM and MLIR have 2 different options with the same name? Do we get 
a compile time error? Or is there a risk that someone might -mllvm -XYZ and it 
would end up in MLIR's XYZ option instead, because we're processing the MLIR 
options after the LLVM ones?




Comment at: flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:15
+#include "mlir/IR/MLIRContext.h"
+#include "mlir/Pass/PassManager.h"
 #include "flang/Frontend/CompilerInstance.h"

Nit: Should these come after the llvm/ headers? (So it's alphabetical except 
for flang, which may go first)



Comment at: flang/test/Driver/mllvm_vs_mmlir.f90:17
+! MLLVM: flang (LLVM option parsing) [options]
+! MLLVM: --print-ir-after-all
+! MLLVM-NOT: --mlir-{{.*}}

Is this the most llvm-ish option we have? I'm concerned that MLIR might also 
decide to add an option that sounds like this (and for sure 
-print-ir-before-all is mentioned in the [[ 
https://mlir.llvm.org/getting_started/Debugging/ |  MLIR docs ]]).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123297

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


[PATCH] D123297: [flang][driver] Add support for -mmlir

2022-04-07 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski created this revision.
awarzynski added a reviewer: rovka.
Herald added subscribers: sdasgup3, wenzhicui, wrengr, Chia-hungDuan, dcaballe, 
cota, teijeong, rdzhabarov, tatianashp, msifontes, jurahul, Kayjukh, grosul1, 
Joonsoo, liufengdb, aartbik, mgester, arpith-jacob, antiagainst, shauheen, 
rriddle, mehdi_amini, mgorny.
Herald added a reviewer: sscalpone.
Herald added projects: Flang, All.
awarzynski requested review of this revision.
Herald added subscribers: cfe-commits, stephenneuendorffer, nicolasvasilache, 
jdoerfert, MaskRay.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123297

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/FrontendOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/FrontendTool/CMakeLists.txt
  flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/mllvm_vs_mmlir.f90

Index: flang/test/Driver/mllvm_vs_mmlir.f90
===
--- /dev/null
+++ flang/test/Driver/mllvm_vs_mmlir.f90
@@ -0,0 +1,18 @@
+! Verify that `-mllvm` options are forwarded to LLVM and `-mmlir` to MLIR
+
+!
+! RUN COMMAND
+!
+! RUN: %flang_fc1  -mmlir --help | FileCheck %s --check-prefix=MLIR
+! RUN: %flang_fc1  -mllvm --help | FileCheck %s --check-prefix=MLLVM
+
+!
+! EXPECTED OUTPUT
+!
+! MLIR: flang (MLIR option parsing) [options]
+! MLIR: --mlir-{{.*}}
+! MLIR-NOT: --print-ir-after-all
+
+! MLLVM: flang (LLVM option parsing) [options]
+! MLLVM: --print-ir-after-all
+! MLLVM-NOT: --mlir-{{.*}}
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -48,6 +48,7 @@
 ! HELP-NEXT: -help  Display available options
 ! HELP-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-NEXT: -mllvm  Additional arguments to forward to LLVM's option processing
+! HELP-NEXT: -mmlir  Additional arguments to forward to MLIR's option processing
 ! HELP-NEXT: -module-dir   Put MODULE files in 
 ! HELP-NEXT: -nocpp Disable predefined and command line preprocessor macros
 ! HELP-NEXT: -o   Write output to 
@@ -123,6 +124,7 @@
 ! HELP-FC1-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-FC1-NEXT: -load Load the named plugin (dynamic shared object)
 ! HELP-FC1-NEXT: -mllvm  Additional arguments to forward to LLVM's option processing
+! HELP-FC1-NEXT: -mmlir  Additional arguments to forward to MLIR's option processing
 ! HELP-FC1-NEXT: -module-dir   Put MODULE files in 
 ! HELP-FC1-NEXT: -module-suffix  Use  as the suffix for module files (the default value is `.mod`)
 ! HELP-FC1-NEXT: -nocpp Disable predefined and command line preprocessor macros
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -48,6 +48,7 @@
 ! CHECK-NEXT: -help Display available options
 ! CHECK-NEXT: -IAdd directory to the end of the list of include search paths
 ! CHECK-NEXT: -mllvm  Additional arguments to forward to LLVM's option processing
+! CHECK-NEXT: -mmlir  Additional arguments to forward to MLIR's option processing
 ! CHECK-NEXT: -module-dir   Put MODULE files in 
 ! CHECK-NEXT: -nocpp Disable predefined and command line preprocessor macros
 ! CHECK-NEXT: -o  Write output to 
Index: flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -11,6 +11,8 @@
 //
 //===--===//
 
+#include "mlir/IR/MLIRContext.h"
+#include "mlir/Pass/PassManager.h"
 #include "flang/Frontend/CompilerInstance.h"
 #include "flang/Frontend/FrontendActions.h"
 #include "flang/Frontend/FrontendPluginRegistry.h"
@@ -148,6 +150,21 @@
 llvm::cl::ParseCommandLineOptions(numArgs + 1, args.get());
   }
 
+  // Honor -mmlir. This should happen AFTER plugins have been loaded!
+  if (!flang->frontendOpts().mlirArgs.empty()) {
+mlir::registerMLIRContextCLOptions();
+mlir::registerPassManagerCLOptions();
+unsigned numArgs = flang->frontendOpts().mlirArgs.size();
+auto args = std::make_unique(numArgs + 2);
+args[0] = "flang (MLIR option parsing)";
+
+for (unsigned i = 0; i != numArgs; ++i)
+  args[i + 1] =