This is an archive of the discontinued LLVM Phabricator instance.

Replace cc1 options '-mdisable-fp-elim' and '-momit-leaf-frame-pointer' with '-mframe-pointer'
ClosedPublic

Authored by ychen on Jan 5 2019, 4:42 AM.

Details

Summary

After D56351 and D64294, frame pointer handling is migrated to tri-state (all, non-leaf, none) in clang driver and on the function attribute. This patch makes the frame pointer handling cc1 option tri-state.

Diff Detail

Event Timeline

ychen created this revision.Jan 5 2019, 4:42 AM
ychen added a comment.Jan 11 2019, 5:58 PM

gentle ping

chandlerc requested changes to this revision.Jan 15 2019, 8:46 PM

Wow, thanks for the cleanups. This is much easier to read as a consequence. And sorry it took a while to get you another round of review. Comments below.

include/clang/Driver/CC1Options.td
270

Should say more Specify which frame pointers to retain (all, non-leaf, none).

lib/Driver/ToolChains/Clang.cpp
577–582

Keep LLVM coding convention naming pattern please.

579–582

This still doesn't make sense to me...

If the user specifies -fomit-frame-point or -fno-omit-frame-pointer *after* -momit-leaf-frame-pointer or -mno-omit-leaf-frame-pointer, then that last flag should win...

I think you need to first get the "base" FP state by checking the main two flags. Then you need to get the "last" FP state by checking *all four flags*. When the last flag is a leaf flag, then the state is determined by the base + the last. When the last flag is not one of the leaf flags, then the last flag fully specifies the result.

I think you can also process these variables into something simpler to test below, essentially handling all the matching logic in one place.

This revision now requires changes to proceed.Jan 15 2019, 8:46 PM
ychen retitled this revision from Replace cc1 options '-mdisable-fp-elim' and '-momit-leaf-frame-pointer' with '-mframe-pointer=' to Replace cc1 options '-mdisable-fp-elim' and '-momit-leaf-frame-pointer' with'-mframe-pointer='.Jan 16 2019, 8:25 PM
ychen edited the summary of this revision. (Show Details)
ychen updated this revision to Diff 182213.Jan 16 2019, 10:55 PM
ychen marked an inline comment as done.

Thanks for the review!

  • address comments
ychen marked 2 inline comments as done.Jan 16 2019, 10:57 PM
ychen added inline comments.
lib/Driver/ToolChains/Clang.cpp
579–582

I see the point here. I didn't do it since it deviates from GCC/intel compiler behavior. Could you please confirm we really want that?

One example from here is : -momit-leaf-frame-pointer -fno-omit-frame-pointer
(https://software.intel.com/en-us/cpp-compiler-developer-guide-and-reference-momit-leaf-frame-pointer)

For GCC/intel, this is frame-pointer=non-leaf, for us, it will be frame-pointer=all

Herald added a project: Restricted Project. · View Herald TranscriptFeb 2 2019, 6:19 PM

This should be rebased after D64294.

ychen updated this revision to Diff 209550.Jul 12 2019, 11:37 AM
ychen retitled this revision from Replace cc1 options '-mdisable-fp-elim' and '-momit-leaf-frame-pointer' with'-mframe-pointer=' to Replace cc1 options '-mdisable-fp-elim' and '-momit-leaf-frame-pointer' with '-mframe-pointer'.Jul 12 2019, 11:47 AM
ychen edited the summary of this revision. (Show Details)
ychen added a reviewer: MaskRay.
MaskRay added inline comments.Jul 14 2019, 8:57 AM
clang/include/clang/Basic/CodeGenOptions.h
120 ↗(On Diff #209550)

We can probably use enum class FramePointerKind { None, NonLeaf, All }; here.. (enum class ClassABI is an example in this file)

clang/lib/CodeGen/CGCall.cpp
1723 ↗(On Diff #209550)

llvm_unreachable can be deleted if a switch statement is used.

clang/lib/Driver/ToolChains/Clang.cpp
49 ↗(On Diff #209550)

This is probably not necessary. The enum is only used in 2 places below.

3961 ↗(On Diff #209550)

llvm_unreachable("unknown FramePointerKind"); can be deleted if a switch statement is used.

clang/lib/Frontend/CompilerInvocation.cpp
845 ↗(On Diff #209550)

I guess this can be deleted now.

-pg + FramePointerKind::None is rejected by the driver.

if (Arg *A = Args.getLastArg(options::OPT_pg))
  if (FPKeepKind == FramePointerKind::None)
    D.Diag(diag::err_drv_argument_not_allowed_with) << "-fomit-frame-pointer"
                                                    << A->getAsString(Args);
ychen marked 5 inline comments as done.Jul 15 2019, 2:53 PM
ychen marked an inline comment as done and an inline comment as not done.Jul 15 2019, 3:22 PM
ychen added inline comments.
clang/lib/Frontend/CompilerInvocation.cpp
845 ↗(On Diff #209550)

This is still needed for clang/test/CodeGen/x86_64-profiling-keep-fp.c to pass.

We could have another patch to address this and update the test.

ychen updated this revision to Diff 209973.Jul 15 2019, 3:25 PM
ychen marked an inline comment as not done.
ychen edited the summary of this revision. (Show Details)
  • Make FramePointerKind enum class.
  • Replace two if-else-if blocks to switch statements.
MaskRay added inline comments.Jul 15 2019, 7:13 PM
clang/lib/CodeGen/CGCall.cpp
1728 ↗(On Diff #209973)

The assert here is not very necessary.

clang/lib/Driver/ToolChains/Clang.cpp
3955 ↗(On Diff #209973)

Add a space after switch.

ychen updated this revision to Diff 210014.Jul 15 2019, 7:29 PM
ychen marked an inline comment as done.
  • update
ychen marked an inline comment as done.Jul 15 2019, 7:29 PM
MaskRay accepted this revision.Jul 15 2019, 9:09 PM
This revision was not accepted when it landed; it landed in state Needs Review.Jul 20 2019, 3:52 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJul 20 2019, 3:52 PM