Skip to content
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,20 @@ New Compiler Flags
only for thread-local variables, and none (which corresponds to the
existing ``-fno-c++-static-destructors`` flag) skips all static
destructors registration.
- The ``-fextend-variable-liveness`` flag has been added to allow for improved
debugging of optimized code. Using ``-fextend-variable-liveness`` will cause
Clang to generate code that tries to preserve the liveness of source variables
through optimizations, meaning that variables will typically be visible in a
debugger more often. The flag has two levels: ``-fextend-variable-liveness``,
or ``-fextend-variable-liveness=all``, extendes the liveness of all user
variables and the ``this`` pointer. Alternatively ``-fextend-this-ptr``, or
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the flag name supported is -fextend-this-ptr-liveness, not -fextend-this-ptr.

I also wonder whether the -fextend-this-ptr-liveness flag carries its weight -- we've historically removed these special-case flags in favor of the more general things, as we did with -fsanitize= for example. I understand that this is being upstreamed from some existing deployment; does the alias help there? Having it around for a shorter time period with an intent to eventually remove it might be reasonable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable to me - the this variant is quite useful for more performance-sensitive cases, but it doesn't need to exist under a separate flag name; changed it.

``-fextend-variable-liveness=this``, has the same behaviour but applies only
to the ``this`` variable in C++ class member functions, meaning its effect is
a strict subset of ``-fextend-variable-liveness``. Note that this flag
modifies the results of optimizations that Clang performs, which will result
in reduced performance in generated code; however, this feature will not
extend the liveness of some variables in cases where doing so would likely
have a severe impact on generated code performance.

Deprecated Compiler Flags
-------------------------
Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/CodeGenOptions.def
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,9 @@ CODEGENOPT(EnableTLSDESC, 1, 0)
/// Bit size of immediate TLS offsets (0 == use the default).
VALUE_CODEGENOPT(TLSSize, 8, 0)

/// The types of variables that we will extend the live ranges of.
ENUM_CODEGENOPT(ExtendVariableLiveness, ExtendVariableLivenessKind, 2, ExtendVariableLivenessKind::None)

/// The default stack protector guard offset to use.
VALUE_CODEGENOPT(StackProtectorGuardOffset, 32, INT_MAX)

Expand Down
6 changes: 6 additions & 0 deletions clang/include/clang/Basic/CodeGenOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ class CodeGenOptions : public CodeGenOptionsBase {
Embed_Marker // Embed a marker as a placeholder for bitcode.
};

enum class ExtendVariableLivenessKind {
None,
This,
All,
};

enum InlineAsmDialectKind {
IAD_ATT,
IAD_Intel,
Expand Down
20 changes: 20 additions & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -4298,6 +4298,26 @@ def stack_usage_file : Separate<["-"], "stack-usage-file">,
Visibility<[CC1Option]>,
HelpText<"Filename (or -) to write stack usage output to">,
MarshallingInfoString<CodeGenOpts<"StackUsageOutput">>;
def fextend_variable_liveness_EQ : Joined<["-"], "fextend-variable-liveness=">,
Group<f_Group>, Visibility<[ClangOption, CC1Option]>,
HelpText<"Extend the liveness of user variables through optimizations to "
"prevent stale or optimized-out variable values when debugging. Can "
"be applied to all user variables, or just to the C++ 'this' ptr. "
"May choose not to extend the liveness of some variables, such as "
"non-scalars larger than 4 unsigned ints, or variables in any "
"inlined functions.">,
Values<"all,this,none">,
NormalizedValues<["All", "This", "None"]>,
NormalizedValuesScope<"CodeGenOptions::ExtendVariableLivenessKind">,
MarshallingInfoEnum<CodeGenOpts<"ExtendVariableLiveness">, "None">;
def fextend_this_ptr_liveness : Flag<["-"], "fextend-this-ptr-liveness">,
Visibility<[ClangOption, CC1Option]>,
Alias<fextend_variable_liveness_EQ>, AliasArgs<["this"]>,
HelpText<"Alias for -fextend-variable-liveness=this.">;
def fextend_variable_liveness : Flag<["-"], "fextend-variable-liveness">,
Visibility<[ClangOption, CC1Option]>,
Alias<fextend_variable_liveness_EQ>, AliasArgs<["all"]>,
HelpText<"Alias for -fextend-variable-liveness=all.">;

defm unique_basic_block_section_names : BoolFOption<"unique-basic-block-section-names",
CodeGenOpts<"UniqueBasicBlockSectionNames">, DefaultFalse,
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7654,6 +7654,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
if (Args.hasArg(options::OPT_fretain_comments_from_system_headers))
CmdArgs.push_back("-fretain-comments-from-system-headers");

Args.AddLastArg(CmdArgs, options::OPT_fextend_variable_liveness_EQ);

// Forward -fcomment-block-commands to -cc1.
Args.AddAllArgs(CmdArgs, options::OPT_fcomment_block_commands);
// Forward -fparse-all-comments to -cc1.
Expand Down
15 changes: 15 additions & 0 deletions clang/test/Driver/extend-variable-liveness.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Tests that -fextend-variable-liveness and its aliases are correctly passed
// by the driver.

// RUN: %clang -### -c %s 2>&1 | FileCheck %s --check-prefixes=CHECK,DEFAULT
// RUN: %clang -fextend-variable-liveness=none -### -c %s 2>&1 | FileCheck %s --check-prefixes=CHECK,NONE
// RUN: %clang -fextend-variable-liveness=this -### -c %s 2>&1 | FileCheck %s --check-prefixes=CHECK,THIS
// RUN: %clang -fextend-this-ptr-liveness -### -c %s 2>&1 | FileCheck %s --check-prefixes=CHECK,THIS
// RUN: %clang -fextend-variable-liveness=all -### -c %s 2>&1 | FileCheck %s --check-prefixes=CHECK,ALL
// RUN: %clang -fextend-variable-liveness -### -c %s 2>&1 | FileCheck %s --check-prefixes=CHECK,ALL

// CHECK: "-cc1"
// DEFAULT-NOT: -fextend-variable-liveness
// NONE-SAME: "-fextend-variable-liveness=none"
// THIS-SAME: "-fextend-variable-liveness=this"
// ALL-SAME: "-fextend-variable-liveness=all"
Loading