[PATCH] D42887: [Driver] Add option to manually control discarding value names in LLVM IR.
This revision was automatically updated to reflect the committed changes. Closed by commit rC324498: [Driver] Add option to manually control discarding value names in LLVM IR. (authored by EricWF, committed by ). Repository: rC Clang https://reviews.llvm.org/D42887 Files: docs/UsersManual.rst include/clang/Driver/Options.td lib/Driver/ToolChains/Clang.cpp test/Driver/clang_f_opts.c Index: docs/UsersManual.rst === --- docs/UsersManual.rst +++ docs/UsersManual.rst @@ -1855,6 +1855,27 @@ must come first.) +Controlling LLVM IR Output +-- + +Controlling Value Names in LLVM IR +^^ + +Emitting value names in LLVM IR increases the size and verbosity of the IR. +By default, value names are only emitted in assertion-enabled builds of Clang. +However, when reading IR it can be useful to re-enable the emission of value +names to improve readability. + +.. option:: -fdiscard-value-names + + Discard value names when generating LLVM IR. + +.. option:: -fno-discard-value-names + + Do not discard value names when generating LLVM IR. This option can be used + to re-enable names for release builds of Clang. + + Comment Parsing Options --- Index: include/clang/Driver/Options.td === --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -790,6 +790,10 @@ HelpText<"Print a template comparison tree for differing templates">; def fdeclspec : Flag<["-"], "fdeclspec">, Group, HelpText<"Allow __declspec as a keyword">, Flags<[CC1Option]>; +def fdiscard_value_names : Flag<["-"], "fdiscard-value-names">, Group, + HelpText<"Discard value names in LLVM IR">, Flags<[DriverOption]>; +def fno_discard_value_names : Flag<["-"], "fno-discard-value-names">, Group, + HelpText<"Do not discard value names in LLVM IR">, Flags<[DriverOption]>; def fdollars_in_identifiers : Flag<["-"], "fdollars-in-identifiers">, Group, HelpText<"Allow '$' in identifiers">, Flags<[CC1Option]>; def fdwarf2_cfi_asm : Flag<["-"], "fdwarf2-cfi-asm">, Group; Index: test/Driver/clang_f_opts.c === --- test/Driver/clang_f_opts.c +++ test/Driver/clang_f_opts.c @@ -517,3 +517,8 @@ // RUN: %clang -### -S %s 2>&1 | FileCheck -check-prefix=CHECK-NO-CF-PROTECTION-BRANCH %s // CHECK-CF-PROTECTION-BRANCH: -fcf-protection=branch // CHECK-NO-CF-PROTECTION-BRANCH-NOT: -fcf-protection=branch + +// RUN: %clang -### -S -fdiscard-value-names %s 2>&1 | FileCheck -check-prefix=CHECK-DISCARD-NAMES %s +// RUN: %clang -### -S -fno-discard-value-names %s 2>&1 | FileCheck -check-prefix=CHECK-NO-DISCARD-NAMES %s +// CHECK-DISCARD-NAMES: "-discard-value-names" +// CHECK-NO-DISCARD-NAMES-NOT: "-discard-value-names" Index: lib/Driver/ToolChains/Clang.cpp === --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -3266,13 +3266,24 @@ if (!C.isForDiagnostics()) CmdArgs.push_back("-disable-free"); -// Disable the verification pass in -asserts builds. #ifdef NDEBUG - CmdArgs.push_back("-disable-llvm-verifier"); - // Discard LLVM value names in -asserts builds. - CmdArgs.push_back("-discard-value-names"); + const bool IsAssertBuild = false; +#else + const bool IsAssertBuild = true; #endif + // Disable the verification pass in -asserts builds. + if (!IsAssertBuild) +CmdArgs.push_back("disable-llvm-verifier"); + + // Discard value names in assert builds unless otherwise specified. + if (const Arg *A = Args.getLastArg(options::OPT_fdiscard_value_names, + options::OPT_fno_discard_value_names)) { +if (A->getOption().matches(options::OPT_fdiscard_value_names)) + CmdArgs.push_back("-discard-value-names"); + } else if (!IsAssertBuild) +CmdArgs.push_back("-discard-value-names"); + // Set the main file name, so that debug info works even with // -save-temps. CmdArgs.push_back("-main-file-name"); Index: docs/UsersManual.rst === --- docs/UsersManual.rst +++ docs/UsersManual.rst @@ -1855,6 +1855,27 @@ must come first.) +Controlling LLVM IR Output +-- + +Controlling Value Names in LLVM IR +^^ + +Emitting value names in LLVM IR increases the size and verbosity of the IR. +By default, value names are only emitted in assertion-enabled builds of Clang. +However, when reading IR it can be useful to re-enable the emission of value +names to improve readability. + +.. option:: -fdiscard-value-names + + Discard value names when generating LLVM IR. + +.. option:: -fno-discard-value-names + + Do not discard value names when generating LLVM IR. This option can be used + to re-enable names for
[PATCH] D42887: [Driver] Add option to manually control discarding value names in LLVM IR.
aaron.ballman accepted this revision. aaron.ballman added a comment. This revision is now accepted and ready to land. LGTM! https://reviews.llvm.org/D42887 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D42887: [Driver] Add option to manually control discarding value names in LLVM IR.
EricWF updated this revision to Diff 133251. EricWF marked an inline comment as done. EricWF added a comment. - Fix documentation as requested. - Put entire statement inside of `#ifdef` blocks. https://reviews.llvm.org/D42887 Files: docs/UsersManual.rst include/clang/Driver/Options.td lib/Driver/ToolChains/Clang.cpp test/Driver/clang_f_opts.c Index: test/Driver/clang_f_opts.c === --- test/Driver/clang_f_opts.c +++ test/Driver/clang_f_opts.c @@ -517,3 +517,8 @@ // RUN: %clang -### -S %s 2>&1 | FileCheck -check-prefix=CHECK-NO-CF-PROTECTION-BRANCH %s // CHECK-CF-PROTECTION-BRANCH: -fcf-protection=branch // CHECK-NO-CF-PROTECTION-BRANCH-NOT: -fcf-protection=branch + +// RUN: %clang -### -S -fdiscard-value-names %s 2>&1 | FileCheck -check-prefix=CHECK-DISCARD-NAMES %s +// RUN: %clang -### -S -fno-discard-value-names %s 2>&1 | FileCheck -check-prefix=CHECK-NO-DISCARD-NAMES %s +// CHECK-DISCARD-NAMES: "-discard-value-names" +// CHECK-NO-DISCARD-NAMES-NOT: "-discard-value-names" Index: lib/Driver/ToolChains/Clang.cpp === --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -3266,13 +3266,24 @@ if (!C.isForDiagnostics()) CmdArgs.push_back("-disable-free"); -// Disable the verification pass in -asserts builds. #ifdef NDEBUG - CmdArgs.push_back("-disable-llvm-verifier"); - // Discard LLVM value names in -asserts builds. - CmdArgs.push_back("-discard-value-names"); + const bool IsAssertBuild = false; +#else + const bool IsAssertBuild = true; #endif + // Disable the verification pass in -asserts builds. + if (!IsAssertBuild) +CmdArgs.push_back("disable-llvm-verifier"); + + // Discard value names in assert builds unless otherwise specified. + if (const Arg *A = Args.getLastArg(options::OPT_fdiscard_value_names, + options::OPT_fno_discard_value_names)) { +if (A->getOption().matches(options::OPT_fdiscard_value_names)) + CmdArgs.push_back("-discard-value-names"); + } else if (!IsAssertBuild) +CmdArgs.push_back("-discard-value-names"); + // Set the main file name, so that debug info works even with // -save-temps. CmdArgs.push_back("-main-file-name"); Index: include/clang/Driver/Options.td === --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -790,6 +790,10 @@ HelpText<"Print a template comparison tree for differing templates">; def fdeclspec : Flag<["-"], "fdeclspec">, Group, HelpText<"Allow __declspec as a keyword">, Flags<[CC1Option]>; +def fdiscard_value_names : Flag<["-"], "fdiscard-value-names">, Group, + HelpText<"Discard value names in LLVM IR">, Flags<[DriverOption]>; +def fno_discard_value_names : Flag<["-"], "fno-discard-value-names">, Group, + HelpText<"Do not discard value names in LLVM IR">, Flags<[DriverOption]>; def fdollars_in_identifiers : Flag<["-"], "fdollars-in-identifiers">, Group, HelpText<"Allow '$' in identifiers">, Flags<[CC1Option]>; def fdwarf2_cfi_asm : Flag<["-"], "fdwarf2-cfi-asm">, Group; Index: docs/UsersManual.rst === --- docs/UsersManual.rst +++ docs/UsersManual.rst @@ -1855,6 +1855,27 @@ must come first.) +Controlling LLVM IR Output +-- + +Controlling Value Names in LLVM IR +^^ + +Emitting value names in LLVM IR increases the size and verbosity of the IR. +By default, value names are only emitted in assertion-enabled builds of Clang. +However, when reading IR it can be useful to re-enable the emission of value +names to improve readability. + +.. option:: -fdiscard-value-names + + Discard value names when generating LLVM IR. + +.. option:: -fno-discard-value-names + + Do not discard value names when generating LLVM IR. This option can be used + to re-enable names for release builds of Clang. + + Comment Parsing Options --- Index: test/Driver/clang_f_opts.c === --- test/Driver/clang_f_opts.c +++ test/Driver/clang_f_opts.c @@ -517,3 +517,8 @@ // RUN: %clang -### -S %s 2>&1 | FileCheck -check-prefix=CHECK-NO-CF-PROTECTION-BRANCH %s // CHECK-CF-PROTECTION-BRANCH: -fcf-protection=branch // CHECK-NO-CF-PROTECTION-BRANCH-NOT: -fcf-protection=branch + +// RUN: %clang -### -S -fdiscard-value-names %s 2>&1 | FileCheck -check-prefix=CHECK-DISCARD-NAMES %s +// RUN: %clang -### -S -fno-discard-value-names %s 2>&1 | FileCheck -check-prefix=CHECK-NO-DISCARD-NAMES %s +// CHECK-DISCARD-NAMES: "-discard-value-names" +// CHECK-NO-DISCARD-NAMES-NOT: "-discard-value-names" Index: lib/Driver/ToolChains/Clang.cpp === --- lib/Driver/ToolChains/Clang.cpp +++
[PATCH] D42887: [Driver] Add option to manually control discarding value names in LLVM IR.
EricWF marked 5 inline comments as done. EricWF added inline comments. Comment at: lib/Driver/ToolChains/Clang.cpp:3269-3274 + const bool IsAssertBuild = #ifdef NDEBUG - CmdArgs.push_back("-disable-llvm-verifier"); - // Discard LLVM value names in -asserts builds. - CmdArgs.push_back("-discard-value-names"); + false; +#else + true; #endif bogner wrote: > It might be a few more characters, but I feel like this is more readable if > you put entire statements in the branches of the #if, ie: > > #ifdef NDEBUG > const bool IsAssertBuild = false; > #else > const bool IsAssertBuild = true; > #endif Ack. Done. Comment at: test/Driver/clang_f_opts.c:522 +// RUN: %clang -### -S -fdiscard-value-names %s 2>&1 | FileCheck -check-prefix=CHECK-DISCARD-NAMES %s +// RUN: %clang -### -S -fno-discard-value-names %s 2>&1 | FileCheck -check-prefix=CHECK-NO-DISCARD-NAMES %s +// CHECK-DISCARD-NAMES: "-discard-value-names" lebedev.ri wrote: > I wonder if it is also possible to check that if neither of > `-f[no-]discard-value-names` is specified, what happens. > The caveat is of course the asserts-vs-no-asserts build type. I don't think so, at least not easily and without changes to the `lit` configuration. It's gone untested this long, I would love to get this patch in without being responsible for adding those tests. https://reviews.llvm.org/D42887 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D42887: [Driver] Add option to manually control discarding value names in LLVM IR.
bogner added inline comments. Comment at: lib/Driver/ToolChains/Clang.cpp:3269-3274 + const bool IsAssertBuild = #ifdef NDEBUG - CmdArgs.push_back("-disable-llvm-verifier"); - // Discard LLVM value names in -asserts builds. - CmdArgs.push_back("-discard-value-names"); + false; +#else + true; #endif It might be a few more characters, but I feel like this is more readable if you put entire statements in the branches of the #if, ie: #ifdef NDEBUG const bool IsAssertBuild = false; #else const bool IsAssertBuild = true; #endif https://reviews.llvm.org/D42887 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D42887: [Driver] Add option to manually control discarding value names in LLVM IR.
aaron.ballman added inline comments. Comment at: docs/UsersManual.rst:1859 +Controlling LLVM IR Output +--- + Underlining is incorrect here (too long). Comment at: docs/UsersManual.rst:1861 + +Controlling Values Names in LLVM IR + s/Values/Value Comment at: docs/UsersManual.rst:1862 +Controlling Values Names in LLVM IR + + Same here. Comment at: docs/UsersManual.rst:1865 +Emitting value names in LLVM IR increases the size and verbosity of the IR. +By default value names are only emitted in assertion enabled builds of Clang. +However, when reading IR it can be useful to re-enable the emission of value By default value -> By default, value in assertion enabled builds -> in assertion-enabled builds https://reviews.llvm.org/D42887 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D42887: [Driver] Add option to manually control discarding value names in LLVM IR.
lebedev.ri added inline comments. Comment at: test/Driver/clang_f_opts.c:522 +// RUN: %clang -### -S -fdiscard-value-names %s 2>&1 | FileCheck -check-prefix=CHECK-DISCARD-NAMES %s +// RUN: %clang -### -S -fno-discard-value-names %s 2>&1 | FileCheck -check-prefix=CHECK-NO-DISCARD-NAMES %s +// CHECK-DISCARD-NAMES: "-discard-value-names" I wonder if it is also possible to check that if neither of `-f[no-]discard-value-names` is specified, what happens. The caveat is of course the asserts-vs-no-asserts build type. https://reviews.llvm.org/D42887 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D42887: [Driver] Add option to manually control discarding value names in LLVM IR.
EricWF marked an inline comment as done. EricWF added inline comments. Comment at: lib/Driver/ToolChains/Clang.cpp:3269 -// Disable the verification pass in -asserts builds. + const bool IsAssertBuild = #ifdef NDEBUG lebedev.ri wrote: > This logic seems sidewards. > If `NDEBUG` is specified, then it is `assert()`-less build. > If `NDEBUG` is *not* specified, then `assert()`'s are actually functional. > Woops! Silly me. Thats a dumb mistake and I feel dumb having made it. https://reviews.llvm.org/D42887 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D42887: [Driver] Add option to manually control discarding value names in LLVM IR.
EricWF updated this revision to Diff 132752. EricWF marked an inline comment as done. EricWF added a comment. - Address really really really dumb mistake. https://reviews.llvm.org/D42887 Files: docs/UsersManual.rst include/clang/Driver/Options.td lib/Driver/ToolChains/Clang.cpp test/Driver/clang_f_opts.c Index: test/Driver/clang_f_opts.c === --- test/Driver/clang_f_opts.c +++ test/Driver/clang_f_opts.c @@ -517,3 +517,8 @@ // RUN: %clang -### -S %s 2>&1 | FileCheck -check-prefix=CHECK-NO-CF-PROTECTION-BRANCH %s // CHECK-CF-PROTECTION-BRANCH: -fcf-protection=branch // CHECK-NO-CF-PROTECTION-BRANCH-NOT: -fcf-protection=branch + +// RUN: %clang -### -S -fdiscard-value-names %s 2>&1 | FileCheck -check-prefix=CHECK-DISCARD-NAMES %s +// RUN: %clang -### -S -fno-discard-value-names %s 2>&1 | FileCheck -check-prefix=CHECK-NO-DISCARD-NAMES %s +// CHECK-DISCARD-NAMES: "-discard-value-names" +// CHECK-NO-DISCARD-NAMES-NOT: "-discard-value-names" Index: lib/Driver/ToolChains/Clang.cpp === --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -3266,12 +3266,23 @@ if (!C.isForDiagnostics()) CmdArgs.push_back("-disable-free"); -// Disable the verification pass in -asserts builds. + const bool IsAssertBuild = #ifdef NDEBUG - CmdArgs.push_back("-disable-llvm-verifier"); - // Discard LLVM value names in -asserts builds. - CmdArgs.push_back("-discard-value-names"); + false; +#else + true; #endif + // Disable the verification pass in -asserts builds. + if (!IsAssertBuild) +CmdArgs.push_back("disable-llvm-verifier"); + + // Discard value names in assert builds unless otherwise specified. + if (const Arg *A = Args.getLastArg(options::OPT_fdiscard_value_names, + options::OPT_fno_discard_value_names)) { +if (A->getOption().matches(options::OPT_fdiscard_value_names)) + CmdArgs.push_back("-discard-value-names"); + } else if (!IsAssertBuild) +CmdArgs.push_back("-discard-value-names"); // Set the main file name, so that debug info works even with // -save-temps. Index: include/clang/Driver/Options.td === --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -790,6 +790,10 @@ HelpText<"Print a template comparison tree for differing templates">; def fdeclspec : Flag<["-"], "fdeclspec">, Group, HelpText<"Allow __declspec as a keyword">, Flags<[CC1Option]>; +def fdiscard_value_names : Flag<["-"], "fdiscard-value-names">, Group, + HelpText<"Discard value names in LLVM IR">, Flags<[DriverOption]>; +def fno_discard_value_names : Flag<["-"], "fno-discard-value-names">, Group, + HelpText<"Do not discard value names in LLVM IR">, Flags<[DriverOption]>; def fdollars_in_identifiers : Flag<["-"], "fdollars-in-identifiers">, Group, HelpText<"Allow '$' in identifiers">, Flags<[CC1Option]>; def fdwarf2_cfi_asm : Flag<["-"], "fdwarf2-cfi-asm">, Group; Index: docs/UsersManual.rst === --- docs/UsersManual.rst +++ docs/UsersManual.rst @@ -1855,6 +1855,27 @@ must come first.) +Controlling LLVM IR Output +--- + +Controlling Values Names in LLVM IR + + +Emitting value names in LLVM IR increases the size and verbosity of the IR. +By default value names are only emitted in assertion enabled builds of Clang. +However, when reading IR it can be useful to re-enable the emission of value +names to improve readability. + +.. option:: -fdiscard-value-names + + Discard value names when generating LLVM IR. + +.. option:: -fno-discard-value-names + + Do not discard value names when generating LLVM IR. This option can be used + to re-enable names for release builds of Clang. + + Comment Parsing Options --- Index: test/Driver/clang_f_opts.c === --- test/Driver/clang_f_opts.c +++ test/Driver/clang_f_opts.c @@ -517,3 +517,8 @@ // RUN: %clang -### -S %s 2>&1 | FileCheck -check-prefix=CHECK-NO-CF-PROTECTION-BRANCH %s // CHECK-CF-PROTECTION-BRANCH: -fcf-protection=branch // CHECK-NO-CF-PROTECTION-BRANCH-NOT: -fcf-protection=branch + +// RUN: %clang -### -S -fdiscard-value-names %s 2>&1 | FileCheck -check-prefix=CHECK-DISCARD-NAMES %s +// RUN: %clang -### -S -fno-discard-value-names %s 2>&1 | FileCheck -check-prefix=CHECK-NO-DISCARD-NAMES %s +// CHECK-DISCARD-NAMES: "-discard-value-names" +// CHECK-NO-DISCARD-NAMES-NOT: "-discard-value-names" Index: lib/Driver/ToolChains/Clang.cpp === --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -3266,12 +3266,23 @@ if (!C.isForDiagnostics())
[PATCH] D42887: [Driver] Add option to manually control discarding value names in LLVM IR.
lebedev.ri added inline comments. Comment at: lib/Driver/ToolChains/Clang.cpp:3269 -// Disable the verification pass in -asserts builds. + const bool IsAssertBuild = #ifdef NDEBUG This logic seems sidewards. If `NDEBUG` is specified, then it is `assert()`-less build. If `NDEBUG` is *not* specified, then `assert()`'s are actually functional. Comment at: lib/Driver/ToolChains/Clang.cpp:3270 -// Disable the verification pass in -asserts builds. + const bool IsAssertBuild = #ifdef NDEBUG - CmdArgs.push_back("-disable-llvm-verifier"); `-assert` is `assert()`-less build https://reviews.llvm.org/D42887 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D42887: [Driver] Add option to manually control discarding value names in LLVM IR.
EricWF created this revision. EricWF added reviewers: erichkeane, aaron.ballman, lebedev.ri. Currently, assertion-disabled Clang builds emit value names when generating LLVM IR. This is controlled by the `NDEBUG` macro, and is not easily overridable. In order to get IR output containing names from a release build of Clang, the user must manually construct the CC1 invocation w/o the `-discard-value-names` option. This is less than ideal. For example, Godbolt uses a release build of Clang, and so when asked to emit LLVM IR the result lacks names, making it harder to read. Manually invoking CC1 on Compiler Explorer is not feasible. This patch adds the driver options `-fdiscard-value-names` and `-fno-discard-value-names` which allow the user to override the default behavior. If neither is specified, the old behavior remains. https://reviews.llvm.org/D42887 Files: docs/UsersManual.rst include/clang/Driver/Options.td lib/Driver/ToolChains/Clang.cpp test/Driver/clang_f_opts.c Index: test/Driver/clang_f_opts.c === --- test/Driver/clang_f_opts.c +++ test/Driver/clang_f_opts.c @@ -517,3 +517,8 @@ // RUN: %clang -### -S %s 2>&1 | FileCheck -check-prefix=CHECK-NO-CF-PROTECTION-BRANCH %s // CHECK-CF-PROTECTION-BRANCH: -fcf-protection=branch // CHECK-NO-CF-PROTECTION-BRANCH-NOT: -fcf-protection=branch + +// RUN: %clang -### -S -fdiscard-value-names %s 2>&1 | FileCheck -check-prefix=CHECK-DISCARD-NAMES %s +// RUN: %clang -### -S -fno-discard-value-names %s 2>&1 | FileCheck -check-prefix=CHECK-NO-DISCARD-NAMES %s +// CHECK-DISCARD-NAMES: "-discard-value-names" +// CHECK-NO-DISCARD-NAMES-NOT: "-discard-value-names" Index: lib/Driver/ToolChains/Clang.cpp === --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -3266,12 +3266,23 @@ if (!C.isForDiagnostics()) CmdArgs.push_back("-disable-free"); -// Disable the verification pass in -asserts builds. + const bool IsAssertBuild = #ifdef NDEBUG - CmdArgs.push_back("-disable-llvm-verifier"); - // Discard LLVM value names in -asserts builds. - CmdArgs.push_back("-discard-value-names"); + true; +#else + false; #endif + // Disable the verification pass in -asserts builds. + if (IsAssertBuild) +CmdArgs.push_back("disable-llvm-verifier"); + + // Discard value names in assert builds unless otherwise specified. + if (const Arg *A = Args.getLastArg(options::OPT_fdiscard_value_names, + options::OPT_fno_discard_value_names)) { +if (A->getOption().matches(options::OPT_fdiscard_value_names)) + CmdArgs.push_back("-discard-value-names"); + } else if (IsAssertBuild) +CmdArgs.push_back("-discard-value-names"); // Set the main file name, so that debug info works even with // -save-temps. Index: include/clang/Driver/Options.td === --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -790,6 +790,10 @@ HelpText<"Print a template comparison tree for differing templates">; def fdeclspec : Flag<["-"], "fdeclspec">, Group, HelpText<"Allow __declspec as a keyword">, Flags<[CC1Option]>; +def fdiscard_value_names : Flag<["-"], "fdiscard-value-names">, Group, + HelpText<"Discard value names in LLVM IR">, Flags<[DriverOption]>; +def fno_discard_value_names : Flag<["-"], "fno-discard-value-names">, Group, + HelpText<"Do not discard value names in LLVM IR">, Flags<[DriverOption]>; def fdollars_in_identifiers : Flag<["-"], "fdollars-in-identifiers">, Group, HelpText<"Allow '$' in identifiers">, Flags<[CC1Option]>; def fdwarf2_cfi_asm : Flag<["-"], "fdwarf2-cfi-asm">, Group; Index: docs/UsersManual.rst === --- docs/UsersManual.rst +++ docs/UsersManual.rst @@ -1855,6 +1855,27 @@ must come first.) +Controlling LLVM IR Output +--- + +Controlling Values Names in LLVM IR + + +Emitting value names in LLVM IR increases the size and verbosity of the IR. +By default value names are only emitted in assertion enabled builds of Clang. +However, when reading IR it can be useful to re-enable the emission of value +names to improve readability. + +.. option:: -fdiscard-value-names + + Discard value names when generating LLVM IR. + +.. option:: -fno-discard-value-names + + Do not discard value names when generating LLVM IR. This option can be used + to re-enable names for release builds of Clang. + + Comment Parsing Options --- Index: test/Driver/clang_f_opts.c === --- test/Driver/clang_f_opts.c +++ test/Driver/clang_f_opts.c @@ -517,3 +517,8 @@ // RUN: %clang -### -S %s 2>&1 | FileCheck -check-prefix=CHECK-NO-CF-PROTECTION-BRANCH %s //