[PATCH] D121374: [flang][driver] Add support for `-mllvm`
This revision was automatically updated to reflect the committed changes. Closed by commit rGa7c08bcf777e: [flang][driver] Add support for `-mllvm` (authored by awarzynski). Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D121374/new/ https://reviews.llvm.org/D121374 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/ExecuteCompilerInvocation.cpp flang/test/Driver/driver-help-hidden.f90 flang/test/Driver/driver-help.f90 flang/test/Driver/mllvm.f90 Index: flang/test/Driver/mllvm.f90 === --- /dev/null +++ flang/test/Driver/mllvm.f90 @@ -0,0 +1,32 @@ +! Test the `-mllvm` option + +! +! RUN COMMAND +! +! 1. Test typical usage. +! RUN: %flang -S -mllvm -print-before-all %s -o - 2>&1 | FileCheck %s --check-prefix=OUTPUT +! RUN: %flang_fc1 -S -mllvm -print-before-all %s -o - 2>&1 | FileCheck %s --check-prefix=OUTPUT + +! 2. Does the option forwarding from `flang-new` to `flang-new -fc1` work? +! RUN: %flang -### -S -mllvm -print-before-all %s -o - 2>&1 | FileCheck %s --check-prefix=OPTION_FORWARDING + +! 3. Test invalid usage (`-print-before` requires an argument) +! RUN: not %flang -S -mllvm -print-before %s -o - 2>&1 | FileCheck %s --check-prefix=INVALID_USAGE + +! +! EXPECTED OUTPUT +! +! OUTPUT: *** IR Dump Before Pre-ISel Intrinsic Lowering (pre-isel-intrinsic-lowering) *** +! OUTPUT-NEXT: ; ModuleID = 'FIRModule' +! OUTPUT-NEXT: source_filename = "FIRModule" + +! Verify that `-mllvm ` is forwarded to flang -fc1 +! OPTION_FORWARDING: flang-new" "-fc1" +! OPTION_FORWARDING-SAME: "-mllvm" "-print-before-all" + +! INVALID_USAGE: flang (LLVM option parsing): for the --print-before option: requires a value! + +!-- +! INPUT +!-- +end program Index: flang/test/Driver/driver-help.f90 === --- flang/test/Driver/driver-help.f90 +++ flang/test/Driver/driver-help.f90 @@ -47,6 +47,7 @@ ! HELP-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV. ! 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: -module-dir Put MODULE files in ! HELP-NEXT: -nocpp Disable predefined and command line preprocessor macros ! HELP-NEXT: -o Write output to @@ -121,6 +122,7 @@ ! HELP-FC1-NEXT: -init-only Only execute frontend initialization ! 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: -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 @@ -47,6 +47,7 @@ ! CHECK-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV. ! 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: -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 @@ -135,6 +135,19 @@ } } + // Honor -mllvm. This should happen AFTER plugins have been loaded! + if (!flang->frontendOpts().llvmArgs.empty()) { +unsigned numArgs = flang->frontendOpts().llvmArgs.size(); +auto args = std::make_unique(numArgs + 2); +args[0] = "flang (LLVM option parsing)"; + +for (unsigned i = 0; i != numArgs; ++i) + args[i + 1] = flang->frontendOpts().llvmArgs[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:
[PATCH] D121374: [flang][driver] Add support for `-mllvm`
awarzynski updated this revision to Diff 414648. awarzynski added a comment. Fix option spelling in test Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D121374/new/ https://reviews.llvm.org/D121374 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/ExecuteCompilerInvocation.cpp flang/test/Driver/driver-help-hidden.f90 flang/test/Driver/driver-help.f90 flang/test/Driver/mllvm.f90 Index: flang/test/Driver/mllvm.f90 === --- /dev/null +++ flang/test/Driver/mllvm.f90 @@ -0,0 +1,32 @@ +! Test the `-mllvm` option + +! +! RUN COMMAND +! +! 1. Test typical usage. +! RUN: %flang -S -mllvm -print-before-all %s -o - 2>&1 | FileCheck %s --check-prefix=OUTPUT +! RUN: %flang_fc1 -S -mllvm -print-before-all %s -o - 2>&1 | FileCheck %s --check-prefix=OUTPUT + +! 2. Does the option forwarding from `flang-new` to `flang-new -fc1` work? +! RUN: %flang -### -S -mllvm -print-before-all %s -o - 2>&1 | FileCheck %s --check-prefix=OPTION_FORWARDING + +! 3. Test invalid usage (`-print-before` requires an argument) +! RUN: not %flang -S -mllvm -print-before %s -o - 2>&1 | FileCheck %s --check-prefix=INVALID_USAGE + +! +! EXPECTED OUTPUT +! +! OUTPUT: *** IR Dump Before Pre-ISel Intrinsic Lowering (pre-isel-intrinsic-lowering) *** +! OUTPUT-NEXT: ; ModuleID = 'FIRModule' +! OUTPUT-NEXT: source_filename = "FIRModule" + +! Verify that `-mllvm ` is forwarded to flang -fc1 +! OPTION_FORWARDING: flang-new" "-fc1" +! OPTION_FORWARDING-SAME: "-mllvm" "-print-before-all" + +! INVALID_USAGE: flang (LLVM option parsing): for the --print-before option: requires a value! + +!-- +! INPUT +!-- +end program Index: flang/test/Driver/driver-help.f90 === --- flang/test/Driver/driver-help.f90 +++ flang/test/Driver/driver-help.f90 @@ -47,6 +47,7 @@ ! HELP-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV. ! 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: -module-dir Put MODULE files in ! HELP-NEXT: -nocpp Disable predefined and command line preprocessor macros ! HELP-NEXT: -o Write output to @@ -121,6 +122,7 @@ ! HELP-FC1-NEXT: -init-only Only execute frontend initialization ! 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: -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 @@ -47,6 +47,7 @@ ! CHECK-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV. ! 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: -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 @@ -135,6 +135,19 @@ } } + // Honor -mllvm. This should happen AFTER plugins have been loaded! + if (!flang->frontendOpts().llvmArgs.empty()) { +unsigned numArgs = flang->frontendOpts().llvmArgs.size(); +auto args = std::make_unique(numArgs + 2); +args[0] = "flang (LLVM option parsing)"; + +for (unsigned i = 0; i != numArgs; ++i) + args[i + 1] = flang->frontendOpts().llvmArgs[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/Frontend/CompilerInvocation.cpp
[PATCH] D121374: [flang][driver] Add support for `-mllvm`
awarzynski added inline comments. Comment at: flang/test/Driver/mllvm.f90:1 +! Test the `-mlvm` option + xbolva00 wrote: > awarzynski wrote: > > xbolva00 wrote: > > > mllvm > > Does it matter? `-mllvm` is consistent with other tests in this directory > > (e.g. > > https://github.com/llvm/llvm-project/blob/main/flang/test/Driver/emit-llvm.f90#L1). > Just typo “mlvm” Sorry, I misread that :/ I thought that you meant `mllvm` instead of `-mllvm`. My bad, thanks for pointing this out! :) Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D121374/new/ https://reviews.llvm.org/D121374 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D121374: [flang][driver] Add support for `-mllvm`
xbolva00 added inline comments. Comment at: flang/test/Driver/mllvm.f90:1 +! Test the `-mlvm` option + awarzynski wrote: > xbolva00 wrote: > > mllvm > Does it matter? `-mllvm` is consistent with other tests in this directory > (e.g. > https://github.com/llvm/llvm-project/blob/main/flang/test/Driver/emit-llvm.f90#L1). Just typo “mlvm” Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D121374/new/ https://reviews.llvm.org/D121374 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D121374: [flang][driver] Add support for `-mllvm`
awarzynski added inline comments. Comment at: flang/test/Driver/mllvm.f90:1 +! Test the `-mlvm` option + xbolva00 wrote: > mllvm Does it matter? `-mllvm` is consistent with other tests in this directory (e.g. https://github.com/llvm/llvm-project/blob/main/flang/test/Driver/emit-llvm.f90#L1). Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D121374/new/ https://reviews.llvm.org/D121374 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D121374: [flang][driver] Add support for `-mllvm`
shraiysh added a comment. LGTM (will let others review as this includes changes to clang too and I am not familiar with it) Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D121374/new/ https://reviews.llvm.org/D121374 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D121374: [flang][driver] Add support for `-mllvm`
xbolva00 added inline comments. Comment at: flang/test/Driver/mllvm.f90:1 +! Test the `-mlvm` option + mllvm Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D121374/new/ https://reviews.llvm.org/D121374 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D121374: [flang][driver] Add support for `-mllvm`
awarzynski created this revision. awarzynski added reviewers: rovka, schweitz, Leporacanthicus, kiranchandramohan, shraiysh. Herald added a reviewer: sscalpone. Herald added a subscriber: dang. Herald added projects: Flang, All. awarzynski requested review of this revision. Herald added subscribers: cfe-commits, jdoerfert. Herald added a project: clang. This option is added in both `flang-new` (the compiler driver) and `flang-new -fc1` (the frontend driver). The semantics are consistent with `clang` and `clang -cc1`. As Flang does not run any LLVM passes when invoked with `-emit-llvm` (i.e. `flang-new -S -emit-llvm `), the tests use `-S`/`-c`/`-emit-obj` instead. These options require an LLVM backend to be run by the driver to generate the output (this makese `-mllvm` relevant here). Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D121374 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/ExecuteCompilerInvocation.cpp flang/test/Driver/driver-help-hidden.f90 flang/test/Driver/driver-help.f90 flang/test/Driver/mllvm.f90 Index: flang/test/Driver/mllvm.f90 === --- /dev/null +++ flang/test/Driver/mllvm.f90 @@ -0,0 +1,32 @@ +! Test the `-mlvm` option + +! +! RUN COMMAND +! +! 1. Test typical usage. +! RUN: %flang -S -mllvm -print-before-all %s -o - 2>&1 | FileCheck %s --check-prefix=OUTPUT +! RUN: %flang_fc1 -S -mllvm -print-before-all %s -o - 2>&1 | FileCheck %s --check-prefix=OUTPUT + +! 2. Does the option forwarding from `flang-new` to `flang-new -fc1` work? +! RUN: %flang -### -S -mllvm -print-before-all %s -o - 2>&1 | FileCheck %s --check-prefix=OPTION_FORWARDING + +! 3. Test invalid usage (`-print-before` requires an argument) +! RUN: not %flang -S -mllvm -print-before %s -o - 2>&1 | FileCheck %s --check-prefix=INVALID_USAGE + +! +! EXPECTED OUTPUT +! +! OUTPUT: *** IR Dump Before Pre-ISel Intrinsic Lowering (pre-isel-intrinsic-lowering) *** +! OUTPUT-NEXT: ; ModuleID = 'FIRModule' +! OUTPUT-NEXT: source_filename = "FIRModule" + +! Verify that `-mllvm ` is forwarded to flang -fc1 +! OPTION_FORWARDING: flang-new" "-fc1" +! OPTION_FORWARDING-SAME: "-mllvm" "-print-before-all" + +! INVALID_USAGE: flang (LLVM option parsing): for the --print-before option: requires a value! + +!-- +! INPUT +!-- +end program Index: flang/test/Driver/driver-help.f90 === --- flang/test/Driver/driver-help.f90 +++ flang/test/Driver/driver-help.f90 @@ -47,6 +47,7 @@ ! HELP-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV. ! 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: -module-dir Put MODULE files in ! HELP-NEXT: -nocpp Disable predefined and command line preprocessor macros ! HELP-NEXT: -o Write output to @@ -121,6 +122,7 @@ ! HELP-FC1-NEXT: -init-only Only execute frontend initialization ! 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: -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 @@ -47,6 +47,7 @@ ! CHECK-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV. ! 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: -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 @@ -135,6 +135,19 @@ } } + // Honor -mllvm. This should happen AFTER plugins have been loaded! + if