This is an archive of the discontinued LLVM Phabricator instance.

[llvm-extract] Add -keep-const-init commandline option
ClosedPublic

Authored by aqjune on Feb 1 2020, 9:39 AM.

Details

Summary

This adds -keep-const-init option to llvm-extract which preserves initializers of
used global constants.

For example:

$ cat a.ll
@g = constant i32 0
define i32 @f() {
  %v = load i32, i32* @g
  ret i32 %v
}

$ llvm-extract --func=f a.ll -S -o -
@g = external constant i32
define i32 @f() { .. }

$ llvm-extract --func=f a.ll -keep-const-init -S -o -
@g = constant i32 0
define i32 @f() { .. }

This option is useful in checking whether a function that uses a constant global is optimized correctly.

Event Timeline

aqjune created this revision.Feb 1 2020, 9:39 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 1 2020, 9:39 AM

A typo in the summary:

define void @f() {     ;;;;;; void -> i32
  %v = load i32, i32* @g
  ret i32 %v
}

How about -keep-constinit -> -keep-const-init?

MaskRay added inline comments.Feb 1 2020, 8:49 PM
llvm/test/tools/llvm-extract/keep-constinit.ll
4

Add a llvm-extract -func foo -S < %s test that @cv is otherwise changed to a declaration.

aqjune updated this revision to Diff 241957.Feb 2 2020, 8:56 PM
  • Use -keep-const-init
  • Update test
aqjune edited the summary of this revision. (Show Details)Feb 2 2020, 8:57 PM
MaskRay accepted this revision.Feb 2 2020, 9:15 PM
This revision is now accepted and ready to land.Feb 2 2020, 9:15 PM
MaskRay retitled this revision from Add -keep-constinit commandline option to llvm-extract to [llvm-extract] Add -keep-constinit commandline option.Feb 2 2020, 9:16 PM
aqjune retitled this revision from [llvm-extract] Add -keep-constinit commandline option to [llvm-extract] Add -keep-const-init commandline option.Feb 2 2020, 9:29 PM
aqjune edited the summary of this revision. (Show Details)
This revision was automatically updated to reflect the committed changes.